QGLViewer
class, which opens an OpenGL
window and lets you draw 3D geometry inside. It handles the mouse to move the camera and defines
some keyboard shortcuts, thus providing the classical functions of a 3D viewer (although everything
can be redefined). QGLViewer
actually inherits from the Qt's QGLWidget
class (use the Qt 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()
method.
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. // It only consists in geometry description, the // GL_MODELVIEW and GL_PROJECTION are handled by the QGLViewer. }
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()
method is actually one of the functions that can be redefined to change
the viewer's behavior. Beginners should read the introduction page.
QGLViewer
class in your applications :
QGLViewer
and overload the methods you need
(init(), draw(), ...
) as is done above. 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.