Glui Manual
Glui Manual
Glui Manual
Version 2.0
June 10, 1999
Contents
Contents...................................................................................................................................................................................2
1 Introduction.....................................................................................................................................................................4
1.1 Overview.................................................................................................................................................................4
1.2 Background.............................................................................................................................................................4
1.3 What’s New in Version 2.0? .................................................................................................................................5
2 Overview .........................................................................................................................................................................5
2.1 Simple Programming Interface..............................................................................................................................5
2.2 Full Integration with GLUT...................................................................................................................................5
2.3 Live Variables.........................................................................................................................................................6
2.4 Callbacks.................................................................................................................................................................6
2.5 Usage for standalone GLUI windows ...................................................................................................................8
2.6 Usage for GLUI subwindows ................................................................................................................................9
2.7 List of Controls.....................................................................................................................................................11
3 Example.........................................................................................................................................................................12
4 API.................................................................................................................................................................................13
4.1 Windows ...............................................................................................................................................................13
4.1.1 Initialization..................................................................................................................................................13
get_version ................................................................................................................................................. 13
create_glui .................................................................................................................................................. 13
create_glui_subwindow............................................................................................................................... 14
set_glutIdleFunc ......................................................................................................................................... 14
set_glutReshapeFunc................................................................................................................................... 15
set_glutKeyboardFunc ................................................................................................................................ 15
set_glutMouseFunc..................................................................................................................................... 15
set_glutSpecialFunc .................................................................................................................................... 15
set_main_gfx_window ................................................................................................................................ 15
4.1.2 Viewport Management ................................................................................................................................16
get_viewport_area....................................................................................................................................... 16
auto_set_viewport....................................................................................................................................... 16
4.1.3 Window management ..................................................................................................................................16
get_glut_window_id.................................................................................................................................... 16
enable, disable............................................................................................................................................. 16
hide ............................................................................................................................................................ 16
show........................................................................................................................................................... 17
close........................................................................................................................................................... 17
close_all ..................................................................................................................................................... 17
sync_live .................................................................................................................................................... 17
sync_live_all............................................................................................................................................... 17
4.2 Controls.................................................................................................................................................................17
4.2.1 Common Functions......................................................................................................................................18
set_name..................................................................................................................................................... 18
set_w, set_h ................................................................................................................................................ 18
get, set ........................................................................................................................................................ 18
disable, enable............................................................................................................................................. 19
set_alignment.............................................................................................................................................. 19
4.2.2 Panels............................................................................................................................................................20
add_panel, add_panel_to_panel ................................................................................................................... 20
4.2.3 Rollouts ........................................................................................................................................................21
add_rollout, add_rollout_to_panel................................................................................................................ 21
4.2.4 Columns........................................................................................................................................................22
add_column, add_column_to_panel ............................................................................................................. 22
4.2.5 Buttons..........................................................................................................................................................23
add_button, add_button_to_panel ................................................................................................................ 23
4.2.6 Checkboxes...................................................................................................................................................24
add_checkbox, add_checkbox_to_panel....................................................................................................... 24
4.2.7 Radio Buttons...............................................................................................................................................25
add_radiogroup, add_radiogroup_to_panel................................................................................................... 25
add_radiobutton_to_group .......................................................................................................................... 25
4.2.8 Static Text.....................................................................................................................................................26
add_statictext, add_statictext_to_panel ........................................................................................................ 26
4.2.9 Editable Text Boxes.....................................................................................................................................27
add_edittext, add_edittext_to_panel ............................................................................................................. 27
set_int_limits, set_float_limits..................................................................................................................... 28
4.2.10 Spinners ........................................................................................................................................................29
add_spinner, add_spinner_to_panel ............................................................................................................. 29
set_int_limits, set_float_limits..................................................................................................................... 30
set_speed.................................................................................................................................................... 30
4.2.11 Separators .....................................................................................................................................................31
add_separator, add_separator_to_panel ........................................................................................................ 31
4.2.12 Rotation Controls.........................................................................................................................................32
add_rotation, add_rotation_to_panel ............................................................................................................ 32
get_float_array_val, set_float_array_val....................................................................................................... 33
set_spin ...................................................................................................................................................... 33
reset............................................................................................................................................................ 33
4.2.13 Translation Controls ....................................................................................................................................34
add_translation, add_translation_to_panel.................................................................................................... 34
get_x, get_y, get_z ...................................................................................................................................... 35
set_x, set_y, set_z ....................................................................................................................................... 35
set_speed.................................................................................................................................................... 35
4.2.14 Listboxes.......................................................................................................................................................36
add_listbox, add_listbox_to_panel ............................................................................................................... 36
add_item..................................................................................................................................................... 36
delete_item ................................................................................................................................................. 37
5 Usage Advice ................................................................................................................................................................38
1 Introduction
1.1 Overview
GLUI is a GLUT-based C++ user interface library which provides controls such as buttons, checkboxes, radio
buttons, spinners, and listboxes to OpenGL applications. It is window-system independent, relying on GLUT to
handle all system-dependent issues, such as window and mouse management. Features of the GLUI User Interface
Library include:
• Complete integration with GLUT toolkit
• Simple creation of a new user interface window with a single line of code
• Support for multiple user interface windows
• Standard user interface controls such as:
§ Buttons
§ Checkboxes for boolean variables
§ Radio Buttons for mutually-exclusive options
§ Editable text boxes for inputting text, integers, and floating-point values
§ Spinners for interactively manipulating integer and floating-point values
§ Arcball controllers for inputting rotation values
§ Translation controllers for inputting X, Y, and Z values
§ Listboxes
§ Static text fields
§ Panels for grouping sets of controls
§ Rollouts (collapsible panels)
§ Separator lines to help visually organize groups of controls
• Controls can generate callbacks when their values change
• Variables can be linked to controls and automatically updated when the value of the control changes (live
variables)
• Controls can be automatically synchronized to reflect changes in live variables
• Controls can trigger GLUT redisplay events when their values change
• Layout and sizing of controls is automatic
• User can cycle through controls using Tab key
1.2 Background
The OpenGL Utility Toolkit (GLUT) is a popular user interface library for OpenGL applications. It provides a
simple interface for handling windows, a mouse, keyboard, and other input devices. It has facilities for nested pop-up
menus, and includes utility functions for bitmap and stroke fonts, as well as for drawing primitive graphics objects
like spheres, tori, and teapots. Its greatest attraction is its window system independence, which (coupled with
OpenGL's own window system independence) provides a very attractive environment for developing cross-platform
graphics applications.
Many applications can be built using only the standard GLUT
input methods - the keyboard, mouse, and pop-up menus. However, as
the number of features and options increases, these methods tend to be
greatly overworked. It is not uncommon to find glut applications where
almost every key on the keyboard is assigned to some function, and
where the pop-up menus are large and cumbersome.
The GLUI User Interface Library addresses this problem by
providing standard user interface elements such as buttons and
checkboxes. The GLUI library is written entirely over GLUT, and
contains no system-dependent code. A GLUI program will therefore
behave the same on SGIs, Windows machines, Macs, or any other
system to which GLUT has been ported. Furthermore, GLUI has been
designed for programming simplicity, allowing user interface elements
to be added with one line of code each.
GLUI version 2.0 includes the following new features and controls:
•GLUI controls within the main graphics window. This makes GLUI compatible with single-window
graphics cards. These GLUI subwindows can be docked to the top, bottom, left, and/or right of the main
graphics window, and they can be stacked as well (i.e., multiple subwindows may be docked to the top, left,
etc.).
•Functions for cleanly destroying GLUI windows and subwindows.
•Functions for hiding and showing GLUI windows and subwindows.
•A sync_live_all()for automatically synchronizing all live variables in all GLUI windows
simultaneously.
•Rollouts – collapsible panels for reducing screen clutter.
•Listboxes – allows the user to choose an item from a list of strings.
•Rotation and translation controllers – for easily receiving 3D interaction input from the user.
2 Overview
GLUI is intended to be a simple yet powerful user interface library. This section describes in more detail its main
features, including a flexible API, easy and full integration with GLUT, live variables, and callbacks.
GLUI has been designed for maximum programming simplicity. New GLUI windows and new controls
within them can be created with a single line of code each. GLUI automatically sizes controls and places them within
their windows. The programmer does not need to explicitly give X, Y, width, and height parameters for each control -
an otherwise cumbersome task.
GLUI provides default values for many parameters in the API. This way, one does not need to place NULL
or dummy values in the argument list when some feature are not needed. As an example, there are several ways to
create a checkbox:
GLUI *glui;
...
glui->add_checkbox("Click me"); Adds a simple checkbox with
the name "Click me"
Note how a default size and position for the checkbox was never specified - GLUI automatically lays out
controls in their window.
GLUI can associate live variables with most types of controls. These are regular C variables that are
automatically updated whenever the user interacts with a GLUI control. For example, a checkbox may have an
associated integer variable, to be automatically toggled between one and zero whenever the user checks or unchecks
the control. A editable text control may maintain an entire character array as a live variable, such that anything the
user types into the text box is automatically copied into the application's character array. This eliminates the need for
the programmer to explicitly query each control's state to determine their current value or contents. In addition, a
GLUI window can send a GLUT redisplay message to another window (i.e., a main graphics window) whenever a
value in the interface is changed. This will cause that other window to redraw, automatically using the new values of
any live variables. For example, a GLUI window can have a spinner to manipulate the radius of an on-screen object.
When the user changes the spinner's value, a live variable (say, float radius) is automatically updated, and the
main graphics window is sent a redisplay message. The graphics window then redraws itself, using the current (that
is, the updated) value of radius - unaware that it was changed since the last frame. Live variables help make the
GLUI interface transparent to the rest of the application.
Live variables are automatically updated by GLUI whenever the user interacts with a control, but what
happens if the user directly changes the value of variable? For example, what if the application changes the radius
with a line such as:
Clearly, the first method will leave the variable and the on-screen control out-of-sync. To remedy this, one
can synchronize live variables. This procedure will check the current value of all live variables in a GLUI window,
and compare them with the controls' current values. If a pair does not match (that is, the user changed a live variable
without telling GLUI), then the control is automatically updated to reflect the variable. Thus, one can make a series
of changes to variables in memory, and then use the single function call sync_live() to synchronize the user
interface:
If a pointer to a live variable is passed to a control creation function (e.g., add_checkbox()), then the
current value of that variable will be used as the initial value for the control. Thus, remember to always properly
initialize live variables (including strings), before passing them to a control creation function.
2.4 Callbacks
GLUI can also generate callbacks whenever the value of a control changes. Upon creation of a new control,
one specifies a function to use as a callback, as well as an integer ID to pass to that function when the control's value
changes. A single function can handle callbacks for multiple controls by using a switch statement to interpret the
incoming ID value within the callback.
2.5 Usage for standalone GLUI windows
Integrating GLUI with a new or existing GLUT application is very straightforward. The steps are:
1. Add the GLUI library to the link line (e.g., glui32.lib for Windows). The proper order in which to add
libraries is: GLUI, GLUT, GLU, OpenGL.
2. #include the file "glui.h" in all sources that will use the GLUI library.
3. Create your regular GLUT windows and popup menus as usual. Make sure to store the window id of
your main graphics window, so GLUI windows can later send it redisplay events:
4. Register your GLUT callbacks as usual (except the Idle callback, discussed below).
5. Register your GLUT idle callback (if any) with GLUI_Master (a global object which is already
declared), to enable GLUI windows to take advantage of idle events without interfering with your
application's idle events. If you do not have an idle callback, pass in NULL.
GLUI_Master.set_glutIdleFunc
( myGlutIdle );
or
GLUI_Master.set_glutIdleFunc
( NULL );
6. In your idle callback, explicitly set the current GLUT window before rendering or posting a redisplay
event. Otherwise the redisplay may accidently be sent to a GLUI window.
Note that flags, x, and y are optional arguments. If they are not specified, default values will be used.
GLUI provides default values for arguments whenever possible.
8. Add controls to the GLUI window. For example, we can add a checkbox and a quit button with:
9. Let each GLUI window you've created know where its main graphics window is:
glui->set_main_gfx_window( window_id );
10. Invoke the standard GLUT main event loop, just as in any GLUT application:
glutMainLoop();
2.6 Usage for GLUI subwindows
Adding GLUI subwindows is slightly more complicated than adding standalone GLUI windows. Since the
graphics application and GLUI share window space, a little extra work is required to ensure that they cooperate
appropriately.
1. Add the GLUI library to the link line (e.g., glui32.lib for Windows). The proper order in which to add libraries
is: GLUI, GLUT, GLU, OpenGL.
2. #include the file "glui.h" in all sources that will use the GLUI library.
3. Create your regular GLUT windows and popup menus as usual. Make sure to store the window id of your main
graphics window, so GLUI windows can later send it redisplay events:
4. Register your GLUT callbacks as usual, except for the Keyboard, Special, Mouse,Reshape, and Idle callbacks.
These four must be registered with GLUI (as described below).
5. Register your GLUT Keyboard, Special, and Mouse callbacks, using the following functions:
GLUI_Master.set_glutKeyboardFunc
( myGlutKeyboard );
GLUI_Master.set_glutSpecialFunc
( myGlutSpecial );
GLUI_Master.set_glutMouseFunc
( myGlutMouse );
GLUI_Master.set_glutReshapeFunc
( myGlutReshape );
Where the “myGlut” functions are replaced by the application’s respective GLUT callbacks.
6. Register your GLUT idle callback (if any) with GLUI, to enable GLUI windows to take advantage of idle events
without interfering with your application's idle events. If you do not have an idle callback, pass in NULL.
GLUI_Master.set_glutIdleFunc
( myGlutIdle );
or
GLUI_Master.set_glutIdleFunc
( NULL );
7. In your idle callback, explicitly set the current GLUT window before rendering or posting a redisplay event.
Otherwise the redisplay may accidently be sent to a GLUI window.
12. Tell the new subwindow which graphics window it should send redisplay events to. For example,
glui_subwin->set_main_gfx_window( window_id );
13. Add controls to the GLUI subwindow.
15. For each graphics window that also contains GLUI subwindows, you need to compensate for the
subwindows when setting the OpenGL viewports. This is done by adding the following code inside the
Reshape callback for the graphics windows:
The above code needs to be used in place of the standard glViewport( 0, 0, w, h )that is found
in most applications. As a shortcut to the above code, one can also use the following code:
GLUI_Master.auto_set_viewport();
16. Invoke the standard GLUT main event loop, just as in any GLUT application:
glutMainLoop();
2.7 List of Controls
Control type Class name Used for... Set/Get values Live var? Callback?
Panel GLUI_Panel grouping controls into boxes - - N
Column GLUI_Column grouping controls into columns - - N
grouping controls into collapsible
Rollout GLUI_Rollout - - N
boxes
Button GLUI_Button invoking user actions - - Y
get_int_val
Checkbox GLUI_Checkbox handling booleans set_int_val
int Y
Radio Group, GLUI_RadioGroup, handling mutually-exclusive get_int_val
Radio Button GLUI_RadioButton options set_int_val
int Y
Static Text GLUI_StaticText plain text labels set_text - N
get_int_val
text that can be edited – and int
set_int_val
optionally interpreted as integers or
Editable Text GLUI_EditText get_float_val Y
floats. Upper and lower bounds set_float_val
float
can be placed on integers and floats
get_text set_text text
Inputting rotation values via an float
Rotation GLUI_Rotation get_float_array_val Y
arcball [16]
get_x float
Translation GLUI_Translation Inputting X, Y, and Z values get_y [1] OR Y
get_z [2]
void myGlutInit();
void myGlutKeyboard(unsigned char Key, int x, int y)
void myGlutMenu( int value )
void myGlutIdle( void )
void myGlutMouse(int button, int button_state, int x, int y )
void myGlutMotion(int x, int y )
void myGlutReshape( int x, int y )
void myGlutDisplay( void );
void control_cb( int ID );
. . .
/** Now create a GLUI user interface window and add controls **/
/** Tell GLUI window which other window to recognize as the main gfx window **/
glui->set_main_gfx_window( main_window );
/** Register the Idle callback with GLUI (instead of with GLUT) **/
GLUI_Master.set_glutIdleFunc ( myGlutIdle );
4.1 Windows
This section describes the functions related to window creation and manipulation. The functions listed here belong to
two classes: GLUI_Master_Objectand GLUI. Keep in mind that any member function of the
GLUI_Master_Objectclass should be invoked from the global object, named GLUI_Master, while any
function of the GLUI class should be invoked via a GLUI pointer returned from
GLUI_Master.create_glui(). For example:
4.1.1 Initialization
get_version
Returns the current GLUI version.
Usage
float GLUI_Master_Object::get_version( void );
create_glui
Creates a new user interface window
Usage
GLUI *GLUI_Master_Object
::create_glui( char *name, int flags=0,
int x=-1, int y=-1 );
Usage
GLUI *GLUI_Master_Object
::create_glui_subwindow( int window,
int position );
GLUI_SUBWINDOW_RIGHT
GLUI_SUBWINDOW_LEFT
GLUI_SUBWINDOW_TOP
GLUI_SUBWINDOW_BOTTOM
You can place any number of subwindows at the same relative position; in this case,
multiple subwindows will simply be stacked on top of one another. For example, if two
subwindows are created inside the same GLUT window, and both use
GLUI_SUBWINDOW_TOP, then the two are placed at the top of the window, although the
first subwindow will be above the second.
set_glutIdleFunc
Registers a standard GLUT Idle callback f() with GLUI. GLUI registers its own Idle callback with GLUT, but
calls this user function f() after each idle event. Thus every idle event is received by the callback f(), but only
after GLUI has done its own idle processing. This is mostly transparent to the GLUT application: simply register the
idle callback with this function rather than the standard GLUT function glutIdleFunc(), and the GLUT
application will work as usual. The only caveat is that under the GLUT specification, the current window is
undefined in an idle callback. Therefore, your application will need to explicitly set the current window before
rendering or posting any GLUT redisplay events:
int main_window;
if ( glutGetWindow() != main_window )
glutSetWindow(main_window);
glutPostRedisplay();
}
This ensures that the redisplay message is properly sent to the graphics window rather than to a GLUI window.
Usage
void GLUI_Master_Object::set_glutIdleFunc(void (*f)(void));
Usage
void GLUI_Master_Object::set_glutReshapeFunc(
void (*f)(int width, int height) );
void GLUI_Master_Object::set_glutKeyboardFunc(
void (*f)(unsigned char key, int x, int y) );
void GLUI_Master_Object::set_glutMouseFunc(
void (*f)(int, int, int, int) );
void GLUI_Master_Object::set_glutSpecialFunc(
void (*f)(int key, int x, int y ) );
set_main_gfx_window
Tells a GLUI window which other (standard GLUT) window to consider the main graphics window. When a control
in the GLUI window changes value, a redisplay request will be sent to this main graphics window.
Usage
void GLUI::set_main_gfx_window( int window_id );
get_viewport_area
Determines the position and dimensions of the drawable area of the current window. This function is needed when
GLUI subwindows are used, since the subwindows will occupy some of the area of a window, which the graphics app
should not overwrite. This function should be called within the GLUT reshape callback function. See Section 2.6 for
an example of using this function
Usage
void GLUI_Master_Object::get_viewport_area(
int *x, int *y, int *w, int *h );
x, y, w, h - When the function returns, these variables will hold the x, y, width, and height of the
drawable area of the current window. These values should then be passed into the
OpenGL viewport command, glViewport().
auto_set_viewport
Automatically sets the viewport for the current window. This single function is equivalent to the following series of
commands:
int x, y, w, h;
GLUI_Master.get_viewport_area
( &x, &y, &w, &h );
glViewport( x, y, w, h );
Usage
void GLUI_Master_Object::auto_set_viewport( void );
get_glut_window_id
Returns the standard GLUT window ID of a GLUI window.
Usage
int GLUI::get_glut_window_id( void );
enable, disable
Enables or disables (grays out) a GLUI window. No controls are active when a GLUI window is disabled.
Usage
void GLUI::enable( void );
void GLUI::disable( void );
hide
Hides a GLUI window or subwindow. A hidden window or subwindow cannot receive any user input.
Usage
void GLUI::hide( void );
show
Unhides a previously-hidden GLUI window or subwindow.
Usage
void GLUI::show( void );
close
Cleanly destroys a GLUI window or subwindow.
Usage
void GLUI::close( void );
close_all
Cleanly destroys all GLUI windows and subwindows. This function is called by the following example code:
GLUI_Master.close_all();
Usage
void GLUI_Master_Object::close_all( void );
sync_live
Synchronizes all live variables associated with a GLUI window. That is, it reads the current value of the live
variables, and sets the associated controls to reflect these variables. More information on live variables and
synchronization, see Section 2.3 above.
Usage
void GLUI::sync_live( void );
sync_live_all
Synchronizes every live variable in every GLUI window. This function steps through each GLUI window and
subwindow, and invokes its sync_live() function. This function is called from the global object,
GLUI_Master:
GLUI_Master.sync_live_all();
Usage
void GLUI_Master_Object::sync_live_all( void );
4.2 Controls
All controls are derived from the base class GLUI_Control. As such, they all are created and operated
similarly. Section 4.2.1 lists functions that are shared by some or all controls, while the rest of Section 0 lists the
specific functions used to create or manage each type of control.
There are two functions to create each type of control. One will be named add_control() (where
control is replaced by the name of the specific control), while the other follows the form
add_control_to_panel(). The second form nests the control within a panel, while the first form places the
control at the top level of the window. Panels are used to group related controls togethers, and panels can be nested
within other panels.
Many controls accept live variables (Section 2.3) and/or callbacks (Section 2.4). To use live variables
(application variables that are automatically updated by the GLUI library), simply pass a pointer to the variable (int,
float, or character string) to the add_control function as the control is created. To use callbacks, pass in both an
integer ID and a callback function. The callback function will be called - with the ID as its single parameter -
whenever the control value changes. Multiple controls can share a callback function, which should then use the ID to
determine which control invoked it.
Within a callback or at any other time, the current value of a control can be retrieved with one of the
functions get_int_val(), get_float_val(), or get_text(), depending on the type of control. For
example, a checkbox stores integer values only, while an editable text box may stores a float, an integer, or plain text,
depending on what type of text box it is. The values of controls can be set using one of set_int_val(),
set_float_val(), set_text(). The documentation for each specific control below list which of these
functions it supports.
set_name
Sets the label on a button, checkbox, etc.
Usage
void GLUI_Control::set_name( char *name );
set_w, set_h
Sets new minimum width/height for a control. set_w() is especially useful to increase the size of the editable text
area in an editable text control or spinner.
Usage
void GLUI_Control::set_w( int new_size );
void GLUI_Control::set_h( int new_size );
get, set
Gets or sets the value of a control. Refer to the individual control descriptions below to see which values can be read
and set for each control.
Usage
int GLUI_Control::get_int_val( void );
Returns: Current integer value of control
Usage
void GLUI_Control::enable( void );
void GLUI_Control::disable( void );
set_alignment
Sets the alignment of a control to left-aligned, right-aligned, or centered.
Usage
void GLUI_Control::set_alignment( int align );
add_panel, add_panel_to_panel
Adds a new panel to a GLUI window, optionally nested within another panel.
Usage
GLUI_Panel *GLUI::add_panel( char *name,
int type = GLUI_PANEL_EMBOSSED);
Rollout, collapsed
Rollout, expanded
Nested rollouts
add_rollout, add_rollout_to_panel
Adds a new rollout to a GLUI window, optionally nested within another rollout or panel.
Usage
GLUI_Rollout *GLUI::add_rollout( char *name, int open = true );
Examples:
glui->add_checkbox("foo");
glui->add_checkbox("bar");
glui->add_column(true);
glui->add_checkbox("Hello");
glui->add_checkbox("World!");
_________________________________________________________________________________
glui->add_checkbox("foo");
glui->add_checkbox("bar");
GLUI_Panel *panel = glui->add_panel
( "Panel" );
glui->add_checkbox_to_panel(panel, "Hello");
glui->add_column_to_panel(panel, true);
glui->add_checkbox_to_panel(panel, "World!");
_________________________________________________________________________________
glui->add_checkbox( "A" );
glui->add_column( false );
glui->add_checkbox( "B" );
glui->add_column( false );
glui->add_checkbox( "C" );
add_column, add_column_to_panel
Begins a new column in a GLUI window, optionally within a panel.
Usage
Button
Button nested within panel
add_button, add_button_to_panel
Adds a new button to a GLUI window, optionally nested within a panel (or rollout)
Usage
Checkbox
Checkbox nested within panel
add_checkbox, add_checkbox_to_panel
Usage
GLUI_Checkbox *GLUI::add_checkbox( char *name,
int *live_var=NULL, int id=-1,
GLUI_Update_CB callback=NULL);
Usage
GLUI_RadioGroup *GLUI::add_radiogroup( int *live_var=NULL,
int user_id=-1,
GLUI_Update_CB callback=NULL);
GLUI_RadioGroup *GLUI::add_radiogroup_to_panel(
GLUI_Panel *panel,
int *live_var=NULL, int user_id=-1,
GLUI_Update_CB callback=
NULL );
add_radiobutton_to_group
Usage
GLUI_RadioButton *GLUI::add_radiobutton_to_group(
GLUI_RadioGroup *group, char name
* );
Static text
Static text nested within panel
add_statictext, add_statictext_to_panel
Usage
GLUI_StaticText *GLUI::add_statictext_to_panel(
GLUI_Panel *panel, char name
* );
add_edittext, add_edittext_to_panel
Usage
GLUI_EditText *GLUI::add_edittext_to_panel(
GLUI_Panel *panel, char *name,
int data_type=GLUI_EDITTEXT_TEXT,
void *live_var=NULL, int id=-1,
GLUI_Update_CB callback=
NULL );
Usage
add_spinner, add_spinner_to_panel
Add a new spinner to a GLUI window.
Usage
Usage
set_speed
This function adjusts the rate at which the spinner changes when it is clicked or when the button is held down. This
function is used to adjust the spinner responsiveness to either fast or slow machines. That is, for very fast machines,
the speed may need to be set to a value less than 1.0, to prevent the spinner from increasing or decreasing too
quickly when the button is held down. Likewise, for very slow machines or for applications with a slow update rate,
the speed may need to be set to some high value to increase the perceived responsiveness of the interface.
Usage
speed - Rate at which spinner changes. It defaults to 1.0. Higher values indicate faster change,
and low values indicate slower change.
4.2.11 Separators
Separators are simple horizontal lines that can be used to divide a series of controls into groups.
Separator
add_separator, add_separator_to_panel
Adds a separator to a GLUI window
Usage
void GLUI::add_separator( void );
Returns: -
4.2.12 Rotation Controls
Rotation controls allow the user to input rotations into an application by manipulating an arcball control. The
control displays as a checkerboard-textured sphere, which the user manipulates directly. The current rotation of the
control is passed to the application as an array of 16 floats, representing a 4×4 rotation matrix. This array can be
passed to OpenGL directly to rotate an object, using the function glMultMatrix(). Note that because this
control deals with pure rotations only (no translation or scaling), the transpose of the 4×4 matrix is the same as its
inverse.
The 16 floats can be retrieved from within an application in two ways. The easiest method is to have GLUI set a
live array automatically, with an optional callback to the application. That is, the application gives GLUI a 16-float
array at the time the rotation control is created. Then, every time the user rotates the arcball, this array is
automatically updated. The second way to retrieve the rotation matrix – without using live variables – is by using
the function GLUI_Rotation::get_float_array_val() (see Section 4.2.1). Likewise, the current
rotation of the control can be set using GLUI_Rotation::set_float_array_val(), which takes as a
parameter a pointer to an array of 16 floats.
If a 16-element float array is passed to a new Rotation control as a live variable, the control will take its initial
rotation from this array (interpreted as a 4×4 matrix). Therefore, the live array needs to be initialized to the identity
matrix before being passed to the GLUI_Rotation::add_rotation() function:
float array[16] = { 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0 , 0.0, 0.0, 0.0, 1.0 };
Alternatively, the control and its associated live array can be initialized to the identity matrix by calling
GLUI_Rotation::reset() after the rotation control is created.
The rotation control can be constrained to horizontal-only movement by holding the CTRL key, or to vertical
rotation by holding the ALT key.
Rotation controls can optionally keep spinning once the user releases the mouse button. To enable this, use the
function GLUI_Rotation::set_spin(). Note that spinning should be disabled in performance-critical
applications (it is disabled by default).
Rotation control
add_rotation, add_rotation_to_panel
Add a new rotation control to a GLUI window.
Usage
GLUI_Rotation *GLUI::add_rotation( char *name,
float *live_var=NULL, int id=-1,
GLUI_Update_CB callback=
NULL );
get_float_array_val, set_float_array_val
Get/set the current rotation.
Usage
void GLUI_Rotation::get_float_array_val( float *array_ptr );
Returns: –
set_spin
Set the damping factor when the arcball is spinning. Higher values indicate less damping. By passing in the
maximum value of 1.0, the arcball will exhibit no damping, and will rotate indefinitely once spun by the user. By
setting the value to 0.0, spinning is disabled altogether. Typical values for the damping factor are .95 – .99.
Note that spinning is disabled by default, since it may slow down performance-critical applications.
Usage
void GLUI_Rotation::set_spin( float damping_factor );
damping_factor - Floating-point value between zero and one. Zero disables spinning, while one
makes the arcball spin indefinitely with no slowdown.
Returns: –
reset
Resets the rotation of the control (sets the rotation matrix to the identity matrix). The damping factor (see
set_spin above) is not changed by this function.
Usage
void GLUI_Rotation::reset( void );
Returns: –
4.2.13 Translation Controls
Translation controls allow the user to manipulate X, Y, and Z values for 3D objects by clicking on on-screen arrows.
The rate of change of translation can be varied by holding down SHIFT for fast movement (100 times faster), or
CTRL for slow movement (100 times slower). The function GLUI_Translation::set_scaling()can be
used to set an overall movement scaling factor.
The four types of translation controls are shown below. When using the XY control (on the left), movement can be
restricted to a single axis (either X or Y) by holding down ALT and clicking on either the horizontal or the vertical
arrows.
add_translation, add_translation_to_panel
Add a new translation control to a GLUI window.
Usage
GLUI_Translation *GLUI::add_translation( char *name, int trans_type,
float *live_var=NULL, int id=-1,
GLUI_Update_CB callback=
NULL );
Usage
float GLUI_Translation::get_x( void );
float GLUI_Translation::get_y( void );
float GLUI_Translation::get_z( void );
set_speed
This function determines how fast a translation control changes in response to user mouse movement. All
translations reported to the user are first multiplied by this speed factor before being passed on to the application.
Applications that need translations to vary slowly should set the speed to a small number below 1.0. Applications
that need large translations should set this scaling factor to some large number. The speed value defaults to 1.0.
Usage
void GLUI_Translation::set_speed( float speed_factor );
speed_factor - Value to multiply all translations by before passing them on to the application
4.2.14 Listboxes
Listbox controls allow the user to choose from a set of text options. When the user clicks on a listbox, a list of text
entries drops down, from which the user selects one. The currently-selected text entry is then displayed in the
listbox.
Listbox
Listbox, selected
Each text entry in a listbox is associated with a numerical ID. This ID is explicitly assigned when the text entry is
added to the listbox. The currently-selected entry can be determined with GLUI_Listbox::get_int_val(),
or set with GLUI_Listbox::set_int_val() .
add_listbox, add_listbox_to_panel
Add a new listbox to a GLUI window.
Usage
add_item
Add a new entry to an existing Listbox.
Usage
id - Numerical ID for this entry. This is the integer value that is returned by the function
GLUI_Listbox::get_int_val(), or set with GLUI_Listbox::set_int_val().
text - Text label for this entry. This string must be less than 300 characters long.
Returns: true if the entry was added to the listbox. Otherwise, false.
delete_item
Delete an entry from an existing Listbox. The entry can be referenced by either its numerical ID or by its text.
Usage
id - Numerical ID for this entry. This is the integer value that is returned by the function
GLUI_Listbox::get_int_val(), or set with GLUI_Listbox::set_int_val().
text - Text label for this entry. This string must be less than 300 characters long.
Returns: true if the entry was found in the listbox, and succesfully removed. Otherwise, false.
5 Usage Advice
• Register your Idle callback with GLUI, not with GLUT. Otherwise, GLUI will be unable to receive idle events
(do not register your idle callback with both GLUI and GLUT, since one will override the other). Also, check
the current window in your Idle callback before rendering or posting a GLUT redisplay event, and set it to the
main graphics window if necessary, since GLUT does not guarantee which will be the current window when an
Idle callback function is called.
• If live variables are used, GLUI will take their value as the initial value for a control. Always initialize your
live variables to some appropriate value before passing them to GLUI. For example, the following code may
initialize a checkbox to an invalid value (neither one or zero):
• String buffers passed to editable text controls must be at least of size sizeof(GLUI_String). Otherwise, a
segmentation fault may occur as GLUI overwrites the buffer.
• Do not pass in a static string as a live variable in an editable text control, as GLUI will attempt to use that space
as a buffer for user-typed text:
char buffer[sizeof(GLUI_String)];
glui->add_edittext( "Text", GLUI_EDITTEXT_TEXT, buffer );
// This will work without crashing
GLUI_String buffer2;
glui->add_edittext( "Text", GLUI_EDITTEXT_TEXT, buffer2 );
// This will also work
• Also, do not pass in a pointer to a local variable as a live variable, as this pointer will be invalid outside the
local function, and a segmentation fault will likely occur.
• The various set/get functions (set_int_val, set_float_val, set_text, get_... ) alter the
current value of a control, and also update any associated live variables. They will not generate a callback.
• During a GLUI callback, the current GLUT window is set to the main graphics window, provided one has been
defined with GLUI::set_main_gfx_window(). If none has been defined, then the current window is
undefined - be sure to explicitly set it to the desired window before executing any OpenGL functions.