class opengl.GLViewport(Widget)
A GLViewport provides basic OpenGL drawing and input handling facilities.
When
using GLViewport, you are responsible for setting up the projection
matrix. For most applications you will probably find it more convenient
to use GLOrtho or GLPerspective.
Mouse Event Handling
Mouse events passed to the mouse handling methods of a GLViewport have an additional attribute called ray. This is a pair of points ((x1, y1, z1), (x2, y2, z2)) obtained by projecting the mouse coordinates onto the near and far planes respectively.
Abstract Methods
- setup_projection()
- This
method is called during drawing and mouse event handling to establish
the projection matrix. When called, the projection matrix is selected
and has been initialised to an identity matrix.
- setup_modelview()
- This method is called during drawing and mouse event handling to establish the modelview matrix. When called,
the modelview matrix is selected and has been initialised to an
identity matrix.
- gl_draw()
- This
method is called after the projection and model-view matrices have been
set up. All OpenGL attributes are saved before calling this method and
restored afterwards, so you can freely change OpenGL state here without
affecting any other GLViewports.
Advanced Methods
The
following methods implement the default drawing mechanism. You can
optionally override them to gain more conrol over the process.
- gl_draw_viewport()
- This
method is called after the viewport has been set up. It is responsible
for establishing the projection and modelview matrices and performing
the drawing. All OpenGL attributes are saved and restored around calls
to this method. The default implementation calls setup_matrices() and
gl_draw().
- setup_matrices()
- This method is called from the default implementation of gl_draw_viewport(). It
is responsible for setting up the projection and modelview matrices.
The default implementation calls setup_projection() and
setup_modelview().
Other Methods
- augment_mouse_event(event)
- This
method is used to add the ray attribute to a mouse event before calling
the corresponding handler. Usually it is called automatically, but you
may want to call it yourself if you receive a mouse event by some means other than the usual channels. Note: This method calls the matrix setup methods, and changes the projection and modelview matrices as a side effect.