init()
function is never called !draw()
function, and the screen remains black. I hate OpenGL !"
draw
, you are in the
world coordinate system: a fixed coordinate system, that is viewed by a moving camera. This
is different (but much more intuitive) from the standard camera-centered OpenGL coordinate
system. To make it simple: the camera displacement and its associated projection matrix are handled by libQGLViewer, so
simply remove any camera related matrix multiplication from the beginning of your
draw()
function.init
function sets the default OpenGL state with glEnable(GL_LIGHTING, GL_FOG,
...)
as you did before.
Also note that libQGLViewer slightly changes the default OpenGL
state (see the QGLViewer::initializeGL()
documentation): GL_LIGHTING
,
GL_LIGHT0
, GL_DEPTHTEST
and GL_COLORMATERIAL
are enabled.
Disable them in your init()
method if desired.
ManipulatedFrame
is a
Frame (position and orientation in 3D) that can directly be moved with the mouse. It is used to move
objects in your scene, see the ManipulatedFrame example.
Frame
class represents a
position and orientation in 3D. These frames can be organized in a tree hierarchy and convenient
conversion functions are provided. The OpenGL code should reflect this organization, as is detailed
in the Frame detailed description.
ManipulatedFrame
(typically stored in a vector
) and use setManipulatedFrame()
to
decide which of them is active at a given time. See the Luxo
example for an illustration.
Note that a ManipulatedFrame
is actually a MouseGrabber
: the frame can be directly manipulated when the mouse goes close to its origin. See the MouseGrabber example for an illustration.
manipulatedFrame
or a MouseGrabber
, depending on the context. By default, events are send to the camera.
With a specific state key (default is the Control
key), it is the manipulatedFrame
that receives the mouse events. Finally, the mouseGrabber
grabs mouse focus when its
MouseGrabber::grabsMouse()
method returns true
(typically when the mouse
hovers). All this can of course be customized (see the mouse page).
You may have to connect additional signals to synchronize viewers' displays. A ManipulatedFrame
displayed
by several viewers should typically have its manipulated
signal connected to the other
viewers' updateGL()
slots.
QGLViewer
constructors'
documentations and the multiView example.
makeCurrent()
to do this. This is
automatically done by the normal refresh loop.
F
key to toggle the frame rate display. It is computed as an average over 30
frames. Since the display is updated only when needed, the frame rate is valid only when you display
in a loop (such as when you move the camera with the mouse).
If you want to know the maximum possible frame rate of your machine on a given scene, you should
setAnimationPeriod(0)
and turn on the animation (by pressing Enter
). The
display will then be updated as quickly as possible, and the frame rate will be meaningful.
qtconfig
to fix this if needed.
init()
function is never called !initializeGL()
. Bad idea since it is this function that
calls init()
in QGLViewer. Move your code to init()
and remove your
initializeGL()
overloading.
Second reason : you call updateGL()
in your constructor, even indirectly. This calls
init()
, but at that point, virtual functions are not defined and it is the
QGLViewer::init()
that is called. Move all OpenGL specific code out of the constructor
to put it in init()
.
renderText
method uses display lists to display characters. If you use more than
2000 display lists, they may overlap. See the drawText
documentation.
GL_LIGHT0
is on and placed at (0,0,0) in the
camera coordinate system. To place a light in your scene, use glLight
as if
you were drawing an object: the current modelView matrix is applied. The following code places a
light in the world coordinate system:
void Viewer::draw() { // ModelView represents the world coordinate system at the beginning of draw() static const GLfloat pos[4] = {1.5, 0.0, 0.0, 1.0}; glLightfv(GL_LIGHT0, GL_POSITION, pos); static const GLfloat spotDir[3] = {-1.0, 0.0, 0.0}; glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, spotDir); // rest of the drawing code... }See also the cameraLight example that makes the camera act as a spot light.
Other questions can be sent by e-mail and will be added to this page. See also the General FAQ.