Home | Documentation | Download | Screenshots | Developer |
QGLViewer
class, which opens an OpenGL window
and lets you draw 3D geometry inside. It handles the mouse and keyboard to move the camera and to define shortcuts,
thus providing some classical functions of a 3D viewer (although everything can be redefined). QGLViewer
actually
inherits from the Qt's QGLWidget
class (use the Qt's assistant
to see its documentation).
class Viewer : public QGLViewer { protected : void draw(); };In your header file, you declare a new class (
Viewer
) which publicly inherits from
QGLViewer
and you redefine the draw()
function.
draw()
function is the heart of your program. Your Viewer
implementation is as simple as this:
#include "viewer.h" void Viewer::draw() { // Your OpenGL 3d code goes here. }
main
function which uses the Viewer
class (most main
functions will be like this, simply cut and paste):
#include <qapplication.h> #include "viewer.h" int main(int argc, char** argv) { // Read command lines arguments. QApplication application(argc,argv); // Instantiate the viewer. Viewer v; // Make the viewer window visible on screen. v.show(); // Set the viewer as the application main widget. application.setMainWidget(&v); // Run main loop. return application.exec(); }
You just have to concentrate on the scene description and on the OpenGL orders that represent it. All the rest comes for free : camera displacement with the mouse in revolve or walk through mode, camera keyFrames paths, screenshots, frame per seconds display, objects of the scene that can be manipulated with the mouse, and much more.
The draw()
function is actually one of the functions that can be redefined to change
the viewer's behavior. You will discover in the feature list some of the
other convenient functions.
QGLViewer
class in your applications :
QGLViewer
and overload the methods you need
(init(), draw(), ...
). The simpleViewer
example is an illustration of this method.QGLViewer
. See the callback example for details.QGLViewer
class emits different signals in its
key methods. When you derive and overload these functions, you replace this behavior by your own implementation.