klampt.vis.glprogram module
Internal classes for building 3D GUI programs.
GLProgram takes care of basic user input.
GLNavigationProgram allows 3D navigation with the mouse.
GLRealtimeProgram calls a subclass-defined idle() function roughly on a constant time step.
- class klampt.vis.glprogram.GLProgramAction(hook, short_text, key, description=None)[source]
Bases:
object
- class klampt.vis.glprogram.GLProgram(name='OpenGL Program')[source]
Bases:
object
A basic OpenGL visualization, run as part of some _GLBackend. For the most part there is a one-to-one correspondence and the backend just relays the input / drawing messages
Assumes that glinit.py has been imported to define _GLBackend.
- name
title of the window (only has an effect before calling run())
- Type:
str
- window
the QtBackend or GLUTBackend instance
- view
describes the OpenGL viewport. If this is provided to an empty _GLBackend window, the w,h gives a hint to the size of the window. It is then updated by the user and setting the viewport size has no effect on the window.
- Type:
- clearColor
the RGBA floating point values of the background color.
- Type:
list of 4 floats
- actions
the list of actions. Must be populated using add_action before init().
- Type:
list of GLProgramAction
- add_action(hook, short_text, key, description=None)[source]
Defines a new generic GUI action. The action will be available in a menu in Qt or as keyboard commands in GLUT.
- run()[source]
Starts a new event loop with this object as the main program. Note: might not return, in the case of GLUT.
- initialize()[source]
Called after the GL context is initialized, but before main loop. May be overridden. Users should not call this directly!
- modifiers()[source]
Retrieves a list of currently pressed keyboard modifiers. Values can be any combination of ‘ctrl’, ‘shift’, ‘alt’.
- keyboardfunc(c, x, y)[source]
Called on keypress down. May be overridden. c is either the ASCII/unicode character of the key pressed or a string describing the character (up,down,left,right, home,end,delete,enter,f1,…,f12)
- keyboardupfunc(c, x, y)[source]
Called on keyboard up (if your system allows it). May be overridden.
- mousewheelfunc(dhorizontal, dvertical, x, y)[source]
Called when the wheel is scrolled. Most wheels have dhorizontal=0. x and y are the position of the mouse when the wheel is scrolled. May be overridden.
- displayfunc()[source]
All OpenGL calls go here. May be overridden, although you may wish to override display() and display_screen() instead.
- idlefunc()[source]
Called on idle. Default value stops all additional idle calls. Must be overridden if you want to do something in the idle loop.
Bases:
GLProgram
A more advanced form of GLProgram that allows you to navigate a camera around a 3D world. Click-drag rotates, Control-drag translates, Shift-drag zooms.
Returns a GLViewport describing the viewport, which could be saved to file.
Sets the viewport to a tuple previously returned by get_view(), e.g. a prior view that was saved to file.
Prepares for OpenGL rendering with the current modelview matrix and default lights.
Sets the default OpenGL lights
Called when the mouse moves on screen. May be overridden.
Called when the mouse is clicked. May be overridden.
Called when the wheel is scrolled. Most wheels have dhorizontal=0. x and y are the position of the mouse when the wheel is scrolled. May be overridden.
- class klampt.vis.glprogram.GLRealtimeProgram(name)[source]
Bases:
GLNavigationProgram
A GLNavigationProgram that refreshes the screen at a given frame rate.
- ttotal
total elapsed time assuming a constant frame rate
- Type:
float
- fps
the frame rate in Hz
- Type:
float
- dt
1.0/fps
- Type:
float
- counter
a frame counter
- Type:
int
- lasttime
time.time() value on the last frame.
- Type:
float
- class klampt.vis.glprogram.GLPluginProgram(name='GLPluginProgram')[source]
Bases:
GLRealtimeProgram
This base class should be used with a GLPluginBase object to handle the GUI functionality (see glcommon.py). Call setPlugin() on this object to set the currently used plugin. pushPlugin()/popPlugin() can also be used to set a hierarchy of plugins.
- set_view(v)[source]
Sets the viewport to a tuple previously returned by get_view(), e.g. a prior view that was saved to file.
- initialize()[source]
Called after the GL context is initialized, but before main loop. May be overridden. Users should not call this directly!
- keyboardfunc(c, x, y)[source]
Called on keypress down. May be overridden. c is either the ASCII/unicode character of the key pressed or a string describing the character (up,down,left,right, home,end,delete,enter,f1,…,f12)
- keyboardupfunc(c, x, y)[source]
Called on keyboard up (if your system allows it). May be overridden.