(new GLUI_Spinner( glui, "Segments:", &segments ))
->set_int_limits( 3, 60 );
glui->set_main_gfx_window( main_window );
/* We register the idle callback with GLUI, *not* with GLUT */
GLUI_Master.set_glutIdleFunc( myGlutIdle );
glutMainLoop();
return EXIT_SUCCESS;
}
example2 效果如图:
主要代码:
[cpp]
void myGlutKeyboard(unsigned char Key, int x, int y)
{
switch(Key)
{
// A few keys here to test the sync_live capability.
case 'o':
// Cycle through object types
++obj %= 3;
GLUI_Master.sync_live_all();
break;
case 'w':
// Toggle wireframe mode
wireframe = !wireframe;
GLUI_Master.sync_live_all();
break;
case 27:
case 'q':
exit(0);
break;
};
glutPostRedisplay();
}
/***************************************** myGlutMenu() ***********/
void myGlutMenu( int value )
{
myGlutKeyboard( value, 0, 0 );
}
/***************************************** myGlutMouse() **********/
void myGlutMouse(int button, int button_state, int x, int y )
{
if ( button == GLUT_LEFT_BUTTON && button_state == GLUT_DOWN ) {
last_x = x;
last_y = y;
}
}
/***************************************** myGlutMotion() **********/
void myGlutMotion(int x, int y )
{
rotationX += (float) (y - last_y);
rotationY += (float) (x - last_x);
last_x = x;
last_y = y;
glutPostRedisplay();
}
/**************************************** myGlutReshape() *************/
void myGlutReshape( int x, int y )
{
glViewport( 0, 0, x, y );
glutPostRedisplay();
}
/***************************************** myGlutDisplay() *****************/
void myGlutDisplay( void )
{
glClearColor( .9f, .9f, .9f, 1.0f );
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glFrustum( -xy_aspect*.08, xy_aspect*.08, -.08, .08, .1, 15.0 );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
glTranslatef( 0.0f, 0.0f, -1.6f );
glRotatef( rotationY, 0.0, 1.0, 0.0 );
glRotatef( rotationX, 1.0, 0.0, 0.0 );
/*** Now we render object, using the variables 'obj', 'segments', and
'wireframe'. These are _live_ variables, which are transparently
updated by GLUI ***/
if ( obj == 0 ) {
if ( wireframe )
glutWireSphere( .6, segments, segments );
else
glutSolidSphere( .6, segments, segments );
}
else if ( obj == 1 ) {
if ( wireframe )
glutWireTorus( .2,.5,16,segments );
else
glutSolidTorus( .2,.5,16,segments );
}
else if ( obj == 2 ) {
if ( wireframe )
glutWireTeapot( .5 );
else
glutSolidTeapot( .5 );
}
glDisable( GL_LIGHTING ); /* Disable lighting while we render text */
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
gluOrtho2D( 0.0, 100.0, 0.0, 100.0 );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
glColor3ub( 0, 0, 0 );
glRasterPos2i( 10, 10 );
// printf( "text: %s\n", text );
/*** Render the live character array 'text' ***/
for (unsigned int i=0; i
glEnable( GL_LIGHTING );
glutSwapBuffers();
}
/**************************************** main() ********************/
int main(int argc, char* argv[])
{
/****************************************/
/* Initialize GLUT and create window *