Graphics Reference
In-Depth Information
an event-polling loop—at which point the application's role becomes limited to
responding to events.
OpenGL itself is window-system-independent and thus has no support for cre-
ating and managing windows or handling events. These types of activities, which
require highly OS-specific techniques, are typically made available to application
programmers via 3rd-party libraries. There are many such libraries, and for this
example we've chosen GLUT (OpenGL Utility Toolkit), which has been very pop-
ular in OpenGL development for decades. In addition, we use the popular GLU
(OpenGL Utility) library for its matrix utilities.
GLUT supports many event types, of which these are the most fundamental.
Display: GLUT calls the registered Display-event handler when it is time
for the application to draw the initial image (i.e., when control has just
been transferred to GLUT's event-polling loop) or whenever the viewport
needs to be refreshed (e.g., to perform “damage repair” as described in
Section 1.11).
Mouse/keyboard/etc.: GLUT calls registered interaction handlers to let
the application know of the user's attempts to interact with the application
through input devices such as the keyboard and mouse.
Idle: To continuously draw new frames as fast as the graphics system can
handle them, an application registers an “idle” handler invoked when the
graphics pipeline is empty and awaiting new commands. This technique
is of value for other purposes as well, such as polling external entities or
performing time-consuming operations.
16.2.2 Initialization and the Main Loop
In Figure 16.2, we show the high-level call-graph structure of a typical OpenGL
application, with yellow boxes representing modules found in the application and
gray boxes representing functions provided by OpenGL and related utilities. Let's
examine this call graph in detail here.
OpenGL library bindings are available for a large variety of languages, but in
this discussion we'll use C/C++ as our example language. Our program's main()
function uses GLUT to perform many of the initialization activities, starting with
an obligatory call to glutInit :
Main
glutMainLoop
Idle
handler
Interaction
handler
Register
event
handlers
Set up
lighting
Set up
camera
Refresh/Redraw
OpenGL state-setting functions
OpenGL drawing functions
Figure 16.2: Structure of a simple OpenGL application.
 
 
 
Search WWH ::




Custom Search