void motion(int x, int y) { OSG::Real32 w = clientWindow->getWidth(), h = clientWindow->getHeight(); OSG::Real32 a = -2. * ( lastx / w - .5 ), b = -2. * ( .5 - lasty / h ), c = -2. * ( x / w - .5 ), d = -2. * ( .5 - y / h ); if ( mouseb & ( 1 << GLUT_LEFT_BUTTON ) ) { tball.updateRotation( a, b, c, d ); } else if ( mouseb & ( 1 << GLUT_MIDDLE_BUTTON ) ) { tball.updatePosition( a, b, c, d ); } else if ( mouseb & ( 1 << GLUT_RIGHT_BUTTON ) ) { tball.updatePositionNeg( a, b, c, d ); } lastx = x; lasty = y; glutPostRedisplay(); }
/*! Simple show text function */ void displayInfo(int x, int y) { int len, i; #ifdef WIN32 #ifdef OSG_WIN32_CL void *font = (void *) 2; #else void *font = 2; #endif #else #ifdef OSG_DEBUG_OLD_C_CASTS void *font = glutBitmap9By15; #else void *font = GLUT_BITMAP_9_BY_15; #endif #endif char text[1024]; sprintf(text, "FPS: %12.1f\n" "Positions: %12u\n" "Triangles: %12u\n" "Geometries: %12u", 1.0/frame_time, sum_positions, sum_triangles, sum_geometries); glPushAttrib(GL_ALL_ATTRIB_BITS); glDisable(GL_LIGHTING); glEnable(GL_COLOR_MATERIAL); glPushMatrix(); glLoadIdentity(); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); gluOrtho2D(0,clientWindow->getWidth(),0,clientWindow->getHeight()); glDisable(GL_DEPTH_TEST); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); int x1=x-5; int x2=x1+24*9+10; int y1=y+14; int y2=y1-4*20; glBegin(GL_QUADS); glColor4f(.1f, .1f, .7f, .5f); glVertex2i(x1,y1); glVertex2i(x1,y2); glVertex2i(x2,y2); glVertex2i(x2,y1); glEnd(); glBegin(GL_LINE_LOOP); glColor3f(1.0, 1.0, 0.0); glVertex2i(x1,y1); glVertex2i(x1,y2); glVertex2i(x2,y2); glVertex2i(x2,y1); glEnd(); glColor3f(1.0, 1.0, 0.0); glRasterPos2f(x, y); len = int(strlen(text)); for (i = 0; i < len; i++) { if(text[i] == '\n') { y-=20; glRasterPos2f(x, y); } else glutBitmapCharacter(font, text[i]); } glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); glPopAttrib(); }