In GLUT, the initialize, draw, and frame routines are known as callbacks implemented with C function pointers. In VR juggler, the equivalent routines are called back using an application object. An application object is a C++ class that defines methods to encapsulate the functionality of the application within a single C++ object.
Draw: OpenGL commands are placed in the draw routine.
The callback function is defined by passing a function
pointer to glutDisplayFunc().
Frame: Operations on application data are done within
the frame routine. No OpenGL commands are allowed here
because the display window is undefined at this point. The
frame function is defined with
glutIdleFunc(). This function generally
does a glutPostRedisplay() to cause the
display callback to be executed.
Init: There is no callback for initialization. Data
initialization is done usually before the application
starts. Context initialization is done during the first run
of the function set with
glutDisplayFunc() (once for each window
opened).
With VR Juggler, no C function pointers are necessary, but a
pointer to an application object must be given to the VR Juggler
kernel. As described in earlier sections of this chapter, the
first step is to derive a new application class from
vrj::GlApp. For more information on
application objects, it may be helpful to review Chapter 2, Application Basics. Briefly, the application class
definition would appear similar to the following:
class MyApplication : public vrj::GlApp
{
...
};The draw, frame, and initialize routine concepts in VR Juggler are presented in the following list.
Draw: An application's display “callback”
function is defined by a new member function called
draw() in the derived class. This
is where OpenGL rendering commands such as
glBegin(),
glVertex(), etc. are placed.
Frame: Calculations such as navigation, collision, physics, artificial intelligence, etc. are often placed in the frame function. The frame function is split across three member functions:
MyApplication::preFrame(),
called before draw()
MyApplication::intraFrame(),
called during draw()
MyApplication::postFrame(),
called after draw()
Init: There is an initialization member function for data and an initialization member function for creating context-specific data (display lists, texture objects). The latter is called for each display context in the system. These two member functions are:
MyApplication::init(),
called once per application startup
MyApplication::contextInit(),
called once per display context creation
Readers who find some of these concepts unfamiliar are encouraged to read the section called “OpenGL Applications”. For information about context-specific data, refer to the section called “Context-Specific Data”.