// This file is part of BOINC. // http://boinc.berkeley.edu // Copyright (C) 2008 University of California // // BOINC is free software; you can redistribute it and/or modify it // under the terms of the GNU Lesser General Public License // as published by the Free Software Foundation, // either version 3 of the License, or (at your option) any later version. // // BOINC is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. // See the GNU Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public License // along with BOINC. If not, see . // Example graphics application, paired with uc2.C // This demonstrates: // - using shared memory to communicate with the worker app // - reading XML preferences by which users can customize graphics // (in this case, select colors) // - handle mouse input (in this case, to zoom and rotate) // - draw text and 3D objects using OpenGL #ifdef _WIN32 #include "boinc_win.h" #else #include #endif #include #include #include "diagnostics.h" #include "gutil.h" #include "boinc_gl.h" #include "graphics2.h" #include "txf_util.h" #include "network.h" #include "gui_rpc_client.h" #include "app_ipc.h" #ifdef __APPLE__ #include "mac_app_icon.h" #endif using std::string; using std::vector; float white[4] = {1., 1., 1., 1.}; TEXTURE_DESC logo; int width, height; // window dimensions bool mouse_down = false; int mouse_x, mouse_y; double pitch_angle, roll_angle, viewpoint_distance=10; float color[4] = {.7, .2, .5, 1}; // the color of the 3D object. // Can be changed using preferences RPC_CLIENT rpc; CC_STATE cc_state; struct APP_SLIDES { string name; int index; double switch_time; vector slides; APP_SLIDES(string n): name(n), index(0), switch_time(0) {} }; struct PROJECT_IMAGES { string url; TEXTURE_DESC icon; vector app_slides; }; vector project_images; // set up lighting model // static void init_lights() { GLfloat ambient[] = {1., 1., 1., 1.0}; GLfloat position[] = {-13.0, 6.0, 20.0, 1.0}; GLfloat dir[] = {-1, -.5, -3, 1.0}; glLightfv(GL_LIGHT0, GL_AMBIENT, ambient); glLightfv(GL_LIGHT0, GL_POSITION, position); glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, dir); } static void draw_logo() { if (logo.present) { float pos[3] = {.2, .3, 0}; float size[3] = {.6, .4, 0}; logo.draw(pos, size, ALIGN_CENTER, ALIGN_CENTER); } } void icon_path(PROJECT* p, char* buf) { char dir[256]; url_to_project_dir((char*)p->master_url.c_str(), dir); sprintf(buf, "%s/stat_icon", dir); } void slideshow(PROJECT* p) { char dir[256], buf[256]; int i; url_to_project_dir((char*)p->master_url.c_str(), dir); for (i=0; i<99; i++) { sprintf(buf, "%s/slideshow_%02d", dir, i); } } PROJECT_IMAGES* get_project_images(PROJECT* p) { unsigned int i; char dir[256], path[256], filename[256]; for (i=0; imaster_url) return π } PROJECT_IMAGES pim; pim.url = p->master_url; url_to_project_dir((char*)p->master_url.c_str(), dir); sprintf(path, "%s/stat_icon", dir); boinc_resolve_filename(path, filename, 256); pim.icon.load_image_file(filename); for (i=0; iapp->user_friendly_name.c_str()); y -= 3; progress.init(prog_pos, 10., 1., 0.8, prog_c, prog_ci); progress.draw(r->fraction_done); mode_unshaded(); sprintf(buf, "%.2f%%", r->fraction_done*100); txf_render_string(.1, x+15, y, 0, 8., white, 0, buf); y -= 3; } void show_coords() { int i; char buf[256]; for (i=-100; i< 101; i+=5) { sprintf(buf, "%d", i); float x = (float)i; txf_render_string(.1, x, 0, 0, 10., white, 0, buf); } for (i=-100; i< 101; i+=5) { sprintf(buf, "%d", i); float y = (float)i; txf_render_string(.1, 0, y, 0, 10., white, 0, buf); } } void show_project(PROJECT* p, float x, float& y) { unsigned int i; PROJECT_IMAGES* pim = get_project_images(p); txf_render_string(.1, x, y, 0, 5., white, 0, (char*)p->project_name.c_str()); if (pim->icon.present) { float pos[3] = {x, y, 1}; float size[2] = {3., 3.}; pim->icon.draw(pos, size, 0, 0); } y -= 3; for (i=0; iproject != p) continue; if (!r->active_task) continue; if (r->active_task_state != PROCESS_EXECUTING) continue; show_result(r, x, y); } } void show_projects() { char buf[256]; float x=-45, y=30; unsigned int i; for (i=0; i