QGLViewer - Introduction

Philosophy

QGLViewer provides 3D application developers some of the classical features of a 3D viewer. See the feature list for details. All the functionalities of the viewer are illustrated by a very simple example which can be used as a cut and paste source for your own applications.

QGLViewer enables you to quickly develop a small test program as well as a complete 3D application. It is versatile and is not designed for any specific application. It it also very convenient as a 3D/OpenGL pedagogical tool.

The QGLViewer class

You will use the library by deriving a viewer class from the QGLViewer main class. For simple applications, all you need to do is to overload the draw() function, which will contain the OpenGL orders that describe your 3D scene. You may want to read a very simple commented program to see exactly how it works.

The different classical functionalities of a 3D viewer (such as a mouse trackball) are provided by the QGLViewer class, and can be overloaded in your own application. Apart from the draw() function, an other good example is the init() function, which can be used to initialize the OpenGL state of your viewer, before the first display. Many other functions can be used as is or redefined, see the feature list for a complete description of the available functions.

Camera and world coordinate system

When you start giving OpenGL orders in your draw() function, you are implicitly located at the origin of the so-called world coordinate system. In libQGLViewer, the camera is an "object" located in this virtual world, that can be moved with the mouse (try to press 'A', the drawAxis() accelerator key to see the world coordinate system). This conception is different (but much more intuitive) from the original camera-centered OpenGL coordinate system.

The viewer associated Camera (accessed using camera()) holds most OpenGL related parameters, such as the projection matrix.

Scene radius and center

QGLViewer is versatile and makes no assumptions on the type of 3D application you are developing. However, in order to implement camera()->showEntireScene(), to set the fly speed in walkthrough mode, to optimally set the ZNear and ZFar of the camera or to tune the stereo display, you need to provide an approximation of your Scene radius, expressed in OpenGL units. This is done using the setSceneRadius() function.

You may also want to tune the Scene center if your scene is not centered on the world coordinate origin (0,0,0).
Default scene radius is 1.0 and the scene center is located at the world origin. These default values may explain why your viewer remains desperately black. Use code like this in your init() function to fit your scene dimensions:

  setSceneRadius(100.0);  // for instance 
  setSceneCenter(400,0,0); // for instance
  camera()->showEntireScene();

Valid XHTML 1.0! Valid CSS! Last modified on Monday, June 13, 2005.