Message boards : API : can any one help me?
Message board moderation
Author | Message |
---|---|
Send message Joined: 7 Nov 08 Posts: 14 |
i followed the uc2_graphics.cpp example and now i can show the background and the 3D part. but the text part which i need is still not avalibale. can any one help me? thanks a lot. i will put my code here: #ifdef _WIN32 #include "boinc_win.h" #include "util.h" // parse_command_line(), boinc_sleep(), dtime()... #include "str_util.h" // parse_command_line() #endif /* BOINC API */ #include "diagnostics.h" #include "boinc_api.h" #include "filesys.h" #include "gutil.h" #include "graphics2.h" #include "boinc_gl.h" #include "txf_util.h" #include "uc2.h" #include "version.h" //#pragma comment(lib,"opengl32.lib") /* Graphics header files */ #ifdef BOINC_APP_GRAPHICS # if defined _WIN32 /* Windows */ # include <gl\glut.h> # elif defined __APPLE_CC__ /* MacOS X */ # include <OpenGL/gl.h> # include <OpenGL/glu.h> # include <GLUT/glut.h> # else /* Unix */ # include <GL/gl.h> # endif # include "graphics_api.h" /* General graphics API for BOINC */ #endif APP_INIT_DATA uc_aid; float color[4] = {.7, .2, .5, 1}; TEXTURE_DESC logo; int width, height; UC_SHMEM* shmem = NULL; float white[4] = {1,1, 1, 1}; double pitch_angle, roll_angle, viewpoint_distance=10; static void parse_project_prefs(char* buf) { char cs[256]; COLOR c; double hue; double max_frames_sec, max_gfx_cpu_pct; if (!buf) return; if (parse_str(buf, "<color_scheme>", cs, 256)) { if (!strcmp(cs, "Tahiti Sunset")) { hue = .9; } else if (!strcmp(cs, "Desert Sands")) { hue = .1; } else { hue = .5; } HLStoRGB(hue, .5, .5, c); color[0] = c.r; color[1] = c.g; color[2] = c.b; color[3] = 1; } if (parse_double(buf, "<max_frames_sec>", max_frames_sec)) { boinc_max_fps = max_frames_sec; } if (parse_double(buf, "<max_gfx_cpu_pct>", max_gfx_cpu_pct)) { boinc_max_gfx_cpu_frac = max_gfx_cpu_pct/100; } } 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); } } static void draw_text() { static float x=0, y=0; static float dx=0.0003, dy=0.0007; char buf[256]; x += dx; y += dy; if (x < 0 || x > .5) dx *= -1; if (y < 0 || y > .5) dy *= -1; double fd = 0, cpu=0, dt; /*if (shmem) { fd = shmem->fraction_done; cpu = shmem->cpu_time; }*/ sprintf(buf, "User:"); txf_render_string(.1, x, y, 0, 500, white, 0, buf); sprintf(buf, "Team:"); txf_render_string(.1, x, y+.1, 0, 500, white, 0, buf); sprintf(buf, "%% Done:"); txf_render_string(.1, x, y+.2, 0, 500, white, 0, buf); sprintf(buf, "CPU time: "); txf_render_string(.1, x, y+.3, 0, 500, white, 0, buf); /*if (shmem) { dt = dtime() - shmem->update_time; if (dt > 10) { boinc_close_window_and_quit(); } else if (dt > 5) { txf_render_string(.1, 0, 0, 0, 500, white, 0, "App not running - exiting in 5 seconds"); } else if (shmem->status.suspended) { txf_render_string(.1, 0, 0, 0, 500, white, 0, "App suspended"); } } else { txf_render_string(.1, 0, 0, 0, 500, white, 0, "No shared mem"); }*/ } static void draw_3d_stuff() { static float x=0, y=0, z=10; static float dx=0.3, dy=0.2, dz=0.5; x += dx; y += dy; z += dz; if (x < -15 || x > 15) dx *= -1; if (y < -15 || y > 15) dy *= -1; if (z < 0 || z > 40) dz *= -1; float pos[3]; pos[0] = x; pos[1] = y; pos[2] = z; drawSphere(pos, 4); drawCylinder(false, pos, 6, 6); } void set_viewpoint(double dist) { double x, y, z; x = 0; y = 3.0*dist; z = 11.0*dist; glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt( x, y, z, // eye position 0,-.8,0, // where we're looking 0.0, 1.0, 0. // up is in positive Y direction ); glRotated(pitch_angle, 1., 0., 0); glRotated(roll_angle, 0., 1., 0); } static void init_camera(double dist) { glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective( 45.0, // field of view in degree 1.0, // aspect ratio 1.0, // Z near clip 1000.0 // Z far ); set_viewpoint(dist); } //---------------------------------- int main(int argc, char **argv) { boinc_init_graphics_diagnostics(BOINC_DIAG_DEFAULTS); #ifdef __APPLE__ setMacIcon(argv[0], MacAppIconData, sizeof(MacAppIconData)); #endif boinc_parse_init_data_file(); boinc_get_init_data(uc_aid); if (uc_aid.project_preferences) { parse_project_prefs(uc_aid.project_preferences); } boinc_graphics_loop(argc, argv); boinc_finish_diag(); } #ifdef BOINC_APP_GRAPHICS /* What to do when the window gets resized. */ void app_graphics_resize(int w, int h){ fprintf(stderr,"GFX: app_graphics_resize(%d, %d) called. \n", w, h); width = w; height = h; glViewport(0, 0, w, h); } /* Initialization of the graphics */ void app_graphics_init() { char path[256]; glClearColor(0.0f, 0.0f, 0.0f, 0.0f); txf_load_fonts("."); boinc_resolve_filename("logo.jpg", path, sizeof(path)); logo.load_image_file(path); init_lights(); fprintf(stderr,"GFX: app_graphics_init() called. \n"); //glClearColor(0.0f, 255.0f, 0.0f, 0.0f); // Green Flash ;-) // glClearDepth(1.0f); // Depth Buffer Setup //glEnable(GL_DEPTH_TEST); // Enables Depth Testing //glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing } /* app_graphics_render() draws whatever is to appear on the screen */ void app_graphics_render(int xs, int ys, double time_of_day) { /*if (shmem == NULL) { shmem = (UC_SHMEM*)boinc_graphics_get_shmem("uppercase"); } if (shmem) { shmem->countdown = 5; }*/ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); mode_unshaded(); mode_ortho(); draw_logo(); ortho_done(); init_camera(viewpoint_distance); scale_screen(width, height); mode_shaded(color); draw_3d_stuff(); mode_unshaded(); mode_ortho(); draw_text(); ortho_done(); /*glClearColor(255.0, 255.0, 0.0, 0.0); // Yellow screen of life //fprintf(stderr,"GFX: app_graphics_render() called. \n"); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glFlush();*/ } #else // BOINC_APP_GRAPHICS /* If no graphics then we have to still provide empty callbacks */ void app_graphics_init() {} void app_graphics_render(int xs, int ys, double time_of_day) {} void app_graphics_resize(int width, int height){} #endif /************************************ * These are empty for now in any case, but you need something there */ /* What to do if the preferences have been reset */ void app_graphics_reread_prefs() {} /* What do do if the mouse is moved: */ void boinc_app_mouse_move(int x, int y, // new coords of cursor int left, // whether buttons are down int middle, int right ){} /* What to do if a mouse button is pressed */ void boinc_app_mouse_button(int x, int y, // coords of cursor int which, // which button (0/1/2) int is_down // true iff button is now down ){} /* What to do if keyboard key is pressed */ void boinc_app_key_press(int, int // platform-specific key encodings! ){} /* What to do if keyboard key is released */ void boinc_app_key_release(int, int // platform-specific key encodings! ){} |
Copyright © 2024 University of California.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License,
Version 1.2 or any later version published by the Free Software Foundation.