1
/****************************************************************************
3
A simple GLUT program using the GLUI User Interface Library
5
This program sets up a checkbox and a spinner, both with live variables.
8
-----------------------------------------------------------------------
10
9/9/98 Paul Rademacher (rademach@cs.unc.edu)
12
****************************************************************************/
18
/** These are the live variables passed into GLUI ***/
24
/***************************************** myGlutIdle() ***********/
26
void myGlutIdle( void )
28
/* According to the GLUT specification, the current window is
29
undefined during an idle callback. So we need to explicitly change
31
if ( glutGetWindow() != main_window )
32
glutSetWindow(main_window);
38
/**************************************** myGlutReshape() *************/
40
void myGlutReshape( int x, int y )
44
xy_aspect = (float)x / (float)y;
45
glViewport( 0, 0, x, y );
47
glMatrixMode( GL_PROJECTION );
49
glFrustum( -xy_aspect*.08, xy_aspect*.08, -.08, .08, .1, 15.0 );
54
/***************************************** myGlutDisplay() *****************/
56
void myGlutDisplay( void )
58
static float rotationX = 0.0, rotationY = 0.0;
60
glClearColor( .9f, .9f, .9f, 1.0f );
61
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
63
/*** Rotate the object ***/
67
glMatrixMode( GL_MODELVIEW );
69
glTranslatef( 0.0, 0.0, -1.0 );
70
glRotatef( rotationY, 0.0, 1.0, 0.0 );
71
glRotatef( rotationX, 1.0, 0.0, 0.0 );
73
/*** Now we render object, using the variables 'segments' and
74
'wireframe'. These are _live_ variables, which are transparently
78
glutWireTorus( .2,.5,16,segments );
80
glutSolidTorus( .2,.5,16,segments );
86
/**************************************** main() ********************/
88
void main(int argc, char* argv[])
90
/****************************************/
91
/* Initialize GLUT and create window */
92
/****************************************/
94
glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
95
glutInitWindowPosition( 50, 50 );
96
glutInitWindowSize( 300, 300 );
98
main_window = glutCreateWindow( "GLUI Example 1" );
99
glutDisplayFunc( myGlutDisplay );
100
glutReshapeFunc( myGlutReshape );
102
/****************************************/
103
/* Set up OpenGL lights */
104
/****************************************/
106
GLfloat light0_ambient[] = {0.1f, 0.1f, 0.3f, 1.0f};
107
GLfloat light0_diffuse[] = {.6f, .6f, 1.0f, 1.0f};
108
GLfloat light0_position[] = {1.0f, 1.0f, 1.0f, 0.0f};
110
glEnable(GL_LIGHTING);
112
glLightfv(GL_LIGHT0, GL_AMBIENT, light0_ambient);
113
glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_diffuse);
114
glLightfv(GL_LIGHT0, GL_POSITION, light0_position);
116
/****************************************/
117
/* Enable z-buferring */
118
/****************************************/
120
glEnable(GL_DEPTH_TEST);
123
/****************************************/
124
/* Here's the GLUI code */
125
/****************************************/
127
GLUI *glui = GLUI_Master.create_glui( "GLUI" );
128
glui->add_checkbox( "Wireframe", &wireframe );
129
GLUI_Spinner *segment_spinner =
130
glui->add_spinner( "Segments:", GLUI_SPINNER_INT, &segments );
131
segment_spinner->set_int_limits( 3, 60 );
133
glui->set_main_gfx_window( main_window );
135
/* We register the idle callback with GLUI, *not* with GLUT */
136
GLUI_Master.set_glutIdleFunc( myGlutIdle );