| | 22 | BOINC supplies a library (libboinc_graphics2.a) that makes it easy |
| | 23 | to develop graphics apps. |
| | 24 | To use this library, the graphics app must call |
| | 25 | {{{ |
| | 26 | boinc_graphics_loop(int argc, char** argv); |
| | 27 | }}} |
| | 28 | after its initialization. |
| | 29 | This function executes an event loop, and does not return. |
| | 30 | |
| | 31 | The application must supply the following functions: |
| | 32 | {{{ |
| | 33 | void app_graphics_render(int xs, ys, double time_of_day); |
| | 34 | void app_graphics_resize(int x, int y); |
| | 35 | void boinc_app_mouse_move(); |
| | 36 | void boinc_app_mouse_button(); |
| | 37 | void boinc_app_key_press(); |
| | 38 | void boinc_app_key_release(); |
| | 39 | }}} |
| | 40 | These functions are described [GraphicsApi here]. |
| | 41 | |
| | 42 | == Communicating with the main application == |
| | 43 | |
| | 44 | Typically the graphics app will want to get information from the main app. |
| | 45 | This can be done efficiently using shared memory. |
| | 46 | The BOINC library supplies the following functions to facilitate this: |
| | 47 | {{{ |
| | 48 | void* boinc_graphics_make_shmem(char* appname, int size); |
| | 49 | void* boinc_graphics_get_shmem(char* appname); |
| | 50 | }}} |
| | 51 | boinc_graphics_make_shmem() (called from the main app) creates a shared memory segment |
| | 52 | of the given size. 'appname' should be the name of this application |
| | 53 | (used to ensure uniqueness of the shared-memory segment name). |
| | 54 | boinc_graphics_get_shmem() (called from the graphics app) attaches to an existing segment. |
| | 55 | |
| | 56 | The contents of the shared memory segment are up to you. |
| | 57 | You may want to include the following items: |
| | 58 | {{{ |
| | 59 | struct UC_SHMEM { |
| | 60 | double update_time; |
| | 61 | double fraction_done; |
| | 62 | double cpu_time; |
| | 63 | BOINC_STATUS status; |
| | 64 | }; |
| | 65 | }}} |
| | 66 | |
| | 67 | update_time:: the time of day when this structure was last modified. This can be used to implement a 'heartbeat' mechanism so that the graphics app will exit if the main app dies. |
| | 68 | fraction_done:: the last fraction done reported by the main app. |
| | 69 | cpu_time:: the last CPU time reported by the main app. |
| | 70 | status:: the BOINC status. If the 'suspended' flag is set, the graphics app should stop changing its display, and simply display an "application suspended" message. |