glLightfv(GL_LIGHT1, GL_POSITION, light1_position);
/****************************************/
/* Enable z-buferring */
/****************************************/
glEnable(GL_DEPTH_TEST);
/****************************************/
/* Here's the GLUI code */
/****************************************/
printf( "GLUI version: %3.2f\n", GLUI_Master.get_version() );
glui = GLUI_Master.create_glui( "GLUI", 0, 400, 50 ); /* name, flags,
x, and y */
new GLUI_StaticText( glui, "GLUI Example 3" );
obj_panel = new GLUI_Panel(glui, "Object" );
/***** Control for the object type *****/
GLUI_Panel *type_panel = new GLUI_Panel( obj_panel, "Type" );
radio = new GLUI_RadioGroup(type_panel,&obj_type,4,control_cb);
new GLUI_RadioButton( radio, "Sphere" );
new GLUI_RadioButton( radio, "Torus" );
new GLUI_RadioButton( radio, "Teapot" );
checkbox =
new GLUI_Checkbox(obj_panel, "Wireframe", &wireframe, 1, control_cb );
spinner =
new GLUI_Spinner( obj_panel, "Segments:", &segments);
spinner->set_int_limits( 3, 60 );
spinner->set_alignment( GLUI_ALIGN_RIGHT );
scale_spinner =
new GLUI_Spinner( obj_panel, "Scale:", &scale);
scale_spinner->set_float_limits( .2f, 4.0 );
scale_spinner->set_alignment( GLUI_ALIGN_RIGHT );
new GLUI_Separator( obj_panel );
edittext = new GLUI_EditText( obj_panel, "Text:", text );
edittext->set_w( 150 );
/******** Add some controls for lights ********/
GLUI_Panel *light0 = new GLUI_Panel( glui, "Light 1" );
GLUI_Panel *light1 = new GLUI_Panel( glui, "Light 2" );
new GLUI_Checkbox( light0, "Enabled", &light0_enabled,
LIGHT0_ENABLED_ID, control_cb );
new GLUI_Spinner( light0, "Intensity:",
&light0_intensity, LIGHT0_INTENSITY_ID,
control_cb );
light0_spinner->set_float_limits( 0.0, 1.0 );
new GLUI_Checkbox( light1, "Enabled", &light1_enabled,
LIGHT1_ENABLED_ID, control_cb );
light1_spinner =
new GLUI_Spinner( light1, "Intensity:",
&light1_intensity, LIGHT1_INTENSITY_ID,
control_cb );
light1_spinner->set_float_limits( 0.0, 1.0 );
light1_spinner->disable(); /* Disable this light initially */
/****** Add a grayed-out counter *****/
GLUI_EditText *counter_edittext =
new GLUI_EditText( glui, "Count:", &counter );
counter_edittext->disable();
/****** Button to Open Command Line Window ******/
open_console_btn =
new GLUI_Button(glui, "Open Console", OPEN_CONSOLE_ID, pointer_cb);
/****** A 'quit' button *****/
new GLUI_Button(glui, "Quit", 0,(GLUI_Update_CB)exit );
/**** Link windows to GLUI, and register idle callback ******/
glui->set_main_gfx_window( main_window );
/* We register the idle callback with GLUI, not with GLUT */
GLUI_Master.set_glutIdleFunc( myGlutIdle );
/**** Regular GLUT main loop ****/
glutMainLoop();
return EXIT_SUCCESS;
}
……
example6 效果如图:
主要的代码:
[cpp]
int main(int argc, char* argv[])
{
glutInit(&argc, argv);
GLUI *edit = GLUI_Master.create_glui("Help on GLUI Widgets", 0);
main_window = edit->get_glut_window_id();
G