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.GLNavigationProgram(name)[source]

Bases: klampt.vis.glprogram.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.

get_view()[source]

Returns a GLViewport describing the viewport, which could be saved to file.

motionfunc(x, y, dx, dy)[source]

Called when the mouse moves on screen. May be overridden.

mousefunc(button, state, x, y)[source]

Called when the mouse is clicked. May be overridden.

prepare_GL()[source]

Prepares for OpenGL rendering with the current modelview matrix and default lights.

set_lights_GL()[source]

Sets the default OpenGL lights

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.

class klampt.vis.glprogram.GLPluginProgram(name='GLPluginProgram')[source]

Bases: klampt.vis.glprogram.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.

display()[source]

Do drawing of objects in world

display_screen()[source]

Do drawing of objects on screen

displayfunc()[source]

All OpenGL calls go here. May be overridden, although you may wish to override display() and display_screen() instead.

idle()[source]
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.

motionfunc(x, y, dx, dy)[source]

Called when the mouse moves on screen. May be overridden.

mousefunc(button, state, x, y)[source]

Called when the mouse is clicked. May be overridden.

popPlugin()[source]
pushPlugin(plugin)[source]
reshapefunc(w, h)[source]

Called on window resize. May be overridden.

setPlugin(plugin)[source]
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.

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

GLViewport

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.

closefunc()[source]

Called by the window when it is closed

display()[source]

Do drawing of objects in world

display_screen()[source]

Do drawing of objects on screen

displayfunc()[source]

All OpenGL calls go here. May be overridden, although you may wish to override display() and display_screen() instead.

draw_text(point, text, size=12, color=None)[source]
get_screen(format='auto', want_depth=False)[source]

Retrieves a screenshot

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.

idlesleep(duration=inf)[source]

Sleeps the idle callback for t seconds. If t is not provided, the idle callback is slept forever

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.

modifiers()[source]

Retrieves a list of currently pressed keyboard modifiers. Values can be any combination of ‘ctrl’, ‘shift’, ‘alt’.

motionfunc(x, y, dx, dy)[source]

Called when the mouse moves on screen. May be overridden.

mousefunc(button, state, x, y)[source]

Called when the mouse is clicked. May be overridden.

prepare_GL()[source]

Prepare drawing in world coordinate frame

prepare_screen_GL()[source]

Prepare drawing on screen

print_help()[source]
refresh()[source]

Call this to redraw the screen on the next event loop

reshape(w, h)[source]

Asks to resize the GL window

reshapefunc(w, h)[source]

Called on window resize. May be overridden.

run()[source]

Starts a new event loop with this object as the main program. Note: might not return, in the case of GLUT.

save_screen(fn, multithreaded=True)[source]

Saves a screenshot

class klampt.vis.glprogram.GLProgramAction(hook, short_text, key, description=None)[source]

Bases: object

class klampt.vis.glprogram.GLRealtimeProgram(name)[source]

Bases: klampt.vis.glprogram.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

idle()[source]
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.