#include #include #include #include #include static GLuint fontbase=0, sphereDL; static GLUquadricObj *sphereObj; static float redMaterial[] = { 1, 0, 0, 1 }; static int *numspheres; static void LoadTextFont(Display *display,char *fontname) { XFontStruct *fontinfo=NULL; fontinfo = XLoadQueryFont(display,fontname); if ((fontinfo) && (!fontinfo->min_byte1) && (!fontinfo->max_byte1)) { fontbase = glGenLists(fontinfo->max_char_or_byte2); glXUseXFont(fontinfo->fid,0,fontinfo->max_char_or_byte2,fontbase); } else fprintf(stderr,"ERROR: failed to load font \"%s\"\n",fontname); } void DrawText(char *string) { if (fontbase) { glPushAttrib(GL_LIST_BIT); glListBase(fontbase); glCallLists(strlen(string),GL_UNSIGNED_BYTE,(GLubyte *)string); glPopAttrib(); } } void init_font(void) { LoadTextFont(CAVEXDisplay(),"fixed"); } void init_ball(void) { glEnable(GL_LIGHT0); glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, redMaterial); sphereObj = gluNewQuadric(); /* gluQuadricDrawStyle(sphereObj, GLU_LINE); */ sphereDL = glGenLists(1); glNewList(sphereDL, GL_COMPILE); gluSphere(sphereObj, 1.0, 32, 32); glEndList(); } void init_all(void) { init_font(); init_ball(); } void draw_text(void) { char str[256]; float pos[3],ori[3]; glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0,10.0,0.0,10.0,-100.0,100.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glColor3f(1.0,1.0,1.0); glRasterPos2f(1.0, 9.0); sprintf(str, "Time: %.1f FPS: %.1f ", *CAVETime,*CAVEFramesPerSecond); DrawText(str); glRasterPos2f(1.0,8.7); CAVEGetPosition(CAVE_HEAD,pos); CAVEGetOrientation(CAVE_HEAD,ori); sprintf(str, "Sensor Position: (%.2f,%.2f,%.2f)" " Orientation:(%.2f,%.2f,%.2f)", pos[0],pos[1],pos[2],ori[0],ori[1],ori[2]); DrawText(str); glRasterPos2f(1.0,8.4); sprintf(str, "Number of spheres: %d", *numspheres); DrawText(str); } void draw_balls(int n) { int i; glEnable(GL_LIGHTING); glPushMatrix(); glTranslatef(-5.0, 5.0, -4.0); for (i = 0; i < n; i++) { glCallList(sphereDL); glTranslatef(-1.0, 0.0, 0.0); } glPopMatrix(); glDisable(GL_LIGHTING); } void draw_all(void) { glClearColor(0.0, 0.0, 0.0, 1.0); glClear(GL_COLOR_BUFFER_BIT); glClear(GL_DEPTH_BUFFER_BIT); draw_balls(*numspheres); draw_text(); } main(int argc, char* argv[]) { CAVEConfigure(&argc, argv, NULL); numspheres = CAVEMalloc(sizeof(int)); *numspheres = 0; CAVEInit(); CAVEInitApplication(init_all, 0); CAVEDisplay(draw_all, 0); while (!CAVEgetbutton(CAVE_ESCKEY)) { if (CAVEButtonChange(1) == 1) { (*numspheres)++; /* printf("increasing to %d\n", *numspheres); */ } if (CAVEButtonChange(3) == 1) { (*numspheres)--; /* printf("decreasing to %d\n", *numspheres); */ } if (CAVEButtonChange(2) == 1) *numspheres = 0; sginap(1); } CAVEExit(); }