From a7ceaa1821636628682484dda30bb862baa5d03c Mon Sep 17 00:00:00 2001 From: David Anderson Date: Fri, 7 Apr 2006 20:00:43 +0000 Subject: [PATCH] *** empty log message *** svn path=/trunk/boinc_samples/; revision=9812 --- README | 1 - checkin_notes | 13 +++ uppercase/upper_case.C | 183 ++++++++++++++++++++++++++++------- win_build/libboincapi.vcproj | 12 +++ 4 files changed, 171 insertions(+), 38 deletions(-) delete mode 100644 README create mode 100644 checkin_notes diff --git a/README b/README deleted file mode 100644 index 56637e1b8a..0000000000 --- a/README +++ /dev/null @@ -1 +0,0 @@ -This module contains the various BOINC sample applications. diff --git a/checkin_notes b/checkin_notes new file mode 100644 index 0000000000..aafada7a70 --- /dev/null +++ b/checkin_notes @@ -0,0 +1,13 @@ +David 7 April 2006 + - extended upper_case so that it draws graphics + (text, image, bouncing ball) + NOTE: to get this to work, you have to put in your build dir: + - file called "logo.jpg" (the image) + - Helvetica.txf + - a file called "in" (any old text) + - added text functions to library + + uppercase/ + upper_case.C + win_build/ + libboincapi.vcproj \ No newline at end of file diff --git a/uppercase/upper_case.C b/uppercase/upper_case.C index 7ba4777a37..f085fe4b6e 100755 --- a/uppercase/upper_case.C +++ b/uppercase/upper_case.C @@ -41,9 +41,13 @@ #include #endif +#define BOINC_APP_GRAPHICS + #ifdef BOINC_APP_GRAPHICS +#include "gutil.h" #include "boinc_gl.h" #include "graphics_api.h" +#include "txf_util.h" #endif #include "diagnostics.h" @@ -58,16 +62,10 @@ using std::string; #define INPUT_FILENAME "in" #define OUTPUT_FILENAME "out" -#ifdef BOINC_APP_GRAPHICS -char display_buf[10]; -double xPos=0, yPos=0; -double xDelta=0.03, yDelta=0.07; -#endif - bool run_slow; bool raise_signal; bool random_exit; -double cpu_time; +double cpu_time=20; APP_INIT_DATA uc_aid; int do_checkpoint(MFILE& mf, int nchars) { @@ -158,9 +156,6 @@ void worker() { c = fgetc(in); if (c == EOF) break; -#ifdef BOINC_APP_GRAPHICS - sprintf(display_buf, "%c -> %c", c, toupper(c)); -#endif c = toupper(c); out._putchar(c); nchars++; @@ -199,7 +194,10 @@ void worker() { } if (cpu_time) { double start = dtime(); - while (dtime() < start + cpu_time) { + while (1) { + double e = dtime()-start; + if (e > cpu_time) break; + boinc_fraction_done(e/cpu_time); use_some_cpu(); } } @@ -235,7 +233,6 @@ int main(int argc, char **argv) { fprintf(stderr, "APP: upper_case: starting, argc %d\n", argc); #ifdef BOINC_APP_GRAPHICS - strcpy(display_buf, "(none)\0"); retval = boinc_init_graphics(worker); if (retval) exit(retval); #else @@ -246,35 +243,147 @@ int main(int argc, char **argv) { } #ifdef BOINC_APP_GRAPHICS -extern GLuint main_font; -void app_init_gl() {} +float white[4] = {1., 1., 1., 1.}; +TEXTURE_DESC logo; +int width, height; -bool app_render(int xs, int ys, double time_of_day) { - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer - glLoadIdentity(); // Reset The Current Modelview Matrix - glColor3f(1,1,1); - - glRasterPos2f(xPos, yPos); - glPrint(main_font, display_buf); - - xPos += xDelta; - yPos += yDelta; - if (xPos < -1 || xPos > 1) xDelta *= -1; - if (yPos < -1 || yPos > 1) yDelta *= -1; - - glRasterPos2f(-0.9, 0.9); - glPrint(main_font, "User: %s", uc_aid.user_name); - - glRasterPos2f(-0.9, 0.8); - glPrint(main_font, "Team: %s", uc_aid.team_name); - - glRasterPos2f(-0.9, 0.7); - glPrint(main_font, "CPU Time: %f", uc_aid.wu_cpu_time); - - return true; // Everything Went OK +static void initlights() { + 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); } +void app_graphics_init() { + glClearColor(0.0f, 0.0f, 0.0f, 0.0f); + txf_load_fonts("."); + logo.load_image_file("logo.jpg"); + initlights(); + int viewport[4]; + get_viewport(viewport); + int w = viewport[2]; + int h = viewport[3]; + app_graphics_resize(w,h); +} + +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; + sprintf(buf, "User: %s", uc_aid.user_name); + txf_render_string(.1, x, y, 0, 500, white, 0, buf); + sprintf(buf, "Team: %s", uc_aid.team_name); + txf_render_string(.1, x, y+.1, 0, 500, white, 0, buf); + sprintf(buf, "%% Done: %f", 100*boinc_get_fraction_done()); + txf_render_string(.1, x, y+.2, 0, 500, white, 0, buf); +} + +static void draw_sphere() { + 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); +} + +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 + ); + +} + +static void app_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); +} + +void app_graphics_render(int xs, int ys, double time_of_day) { + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + mode_unshaded(); + mode_ortho(); + draw_logo(); + ortho_done(); + + app_init_camera(10); + scale_screen(width, height); + GLfloat color[4] = {.7, .2, .5, 1}; + mode_shaded(color); + draw_sphere(); + + scale_screen(width, height); + mode_unshaded(); + mode_ortho(); + draw_text(); + ortho_done(); +} + +void app_graphics_resize(int w, int h){ + width = w; + height = h; + glViewport(0, 0, w, h); +} +void app_graphics_reread_prefs(){} +void boinc_app_mouse_move( + int x, int y, // new coords of cursor + bool left, // whether left mouse button is down + bool middle, + bool right + ){} + +void boinc_app_mouse_button( + int x, int y, // coords of cursor + int which, // which button (0/1/2) + bool is_down // true iff button is now down + ){} + +void boinc_app_key_press( + int, int // system-specific key encodings + ){} + +void boinc_app_key_release( + int, int // system-specific key encodings + ){} + #endif const char *BOINC_RCSID_33ac47a071 = "$Id$"; diff --git a/win_build/libboincapi.vcproj b/win_build/libboincapi.vcproj index f8ee190bdb..e76df2ad0c 100644 --- a/win_build/libboincapi.vcproj +++ b/win_build/libboincapi.vcproj @@ -155,9 +155,15 @@ + + + + + + + +