Chapter 4. Writing Applications

Table of Contents

Application Review
Basic Application Information
Draw Manager-Specific Application Classes
Getting Input
How to Get Input
Where to Get Input
Tutorial: Getting Input
OpenGL Applications
Clearing the Color and Depth Buffers
OpenGL Drawing: vrj::GlApp::draw()
Tutorial: Drawing a Cube with OpenGL
Context-Specific Data
Using Context-Specific Data
Context-Specific Data Details
Tutorial: Drawing a Cube using OpenGL Display Lists
OpenGL Performer Applications
Scene Graph Initialization: vrj::PfApp::initScene()
Scene Graph Access: vrj::PfApp::getScene()
Tutorial: Loading a Model with OpenGL Performer
Other vrj::PfApp Methods
OpenSG Applications
Scene Graph Initialization: vrj::OpenSGApp::initScene()
Scene Graph Access: vrj::OpenSGApp::getSceneRoot()
Tutorial: Loading a Model with OpenSG
VTK Applications

This chapter alone comprises the bulk of information about application development. Each section outlines one area of interest for application developers. For example, there are sections that show how to get input from the system and others that show how to write applications for each of the currently supported graphics APIs. Please note that when writing an application, there will be overlap between these sections. For example, an application that needs input, sound, and OpenGL graphics will be based on concepts from each of the relevant sections.

Application Review

Before getting into too much detail, we present this section as a review from earlier chapters. There is no new information here; it is simply a quick overview of the basics of VR Juggler applications.

Basic Application Information

As described in previous chapters (see Chapter 1, Getting Started, for example), all VR Juggler applications derive from a base application object class (vrj::App). This class defines the basic interface that VR Juggler expects from all application objects. This means that when constructing an application, the user-defined application object must inherit from vrj::App or from a Draw Manager-specific application class that has vrj::App as a superclass. For example:

class userApp : public vrj::App
{
public:
   init();
   preFrame();
   postFrame();
}

This defines a new application class (userApp), instances of which can be used anywhere that VR Juggler expects an application object.

Draw Manager-Specific Application Classes

A user application does not have to (and in most cases does not) derive from vrj::App directly. In almost all cases, an application class is derived from a Draw Manager-specific application class. For example:

class userGlApp : public vrj::GlApp
{
public:
   init();
   preFrame();
   postFrame();
   
   draw();
}

This is an example of an OpenGL application. The application class (userGlApp) has derived directly from the OpenGL Draw Manager-specific vrj::GlApp application base class. This class provides extra definitions in the interface that are custom for OpenGL applications.