This is an old revision of the document!


The project comes with a set of examples showing the different possibility of QGLViewer. These examples are simply the translation of QGLViewer examples into python.

Simple example

The simplest application example.

A Viewer class is derived from QGLViewer and its draw() function is overloaded to specify the user defined OpenGL commands that describe the scene.

This example can be cut and pasted to start the development of a new application.

import OpenGL.GL as ogl
import math
def draw_qgl_logo(nbSteps = 200.0):
    for i in range(0,int(nbSteps)):
        ratio = i/float(nbSteps)
        angle = 21.0*ratio
        c = math.cos(angle)
        s = math.sin(angle)
        r1 = 1.0 - 0.8*ratio
        r2 = 0.8 - 0.8*ratio
        alt = ratio - 0.5
        nor = 0.5
        up = math.sqrt(1.0-nor*nor)
        ogl.glColor3f(1.0-ratio, 0.2 , ratio)
        ogl.glNormal3f(nor*c, up, nor*s)
        ogl.glVertex3f(r1*c, alt, r1*s)
        ogl.glVertex3f(r2*c, alt+0.05, r2*s)

from PyQt4.QtGui import *
from PyQGLViewer import *
from qgllogo import draw_qgl_logo
helpstr = """<h2>S i m p l e V i e w e r</h2>
Use the mouse to move the camera around the object. 
You can respectively revolve around, zoom and translate with the three mouse buttons. 
Left and middle buttons pressed together rotate around the camera view direction axis<br><br>
Pressing <b>Alt</b> and one of the function keys (<b>F1</b>..<b>F12</b>) defines a camera keyFrame. 
Simply press the function key again to restore it. Several keyFrames define a 
camera path. Paths are saved when you quit the application and restored at next start.<br><br>
Press <b>F</b> to display the frame rate, <b>A</b> for the world axis, 
<b>Alt+Return</b> for full screen mode and <b>Control+S</b> to save a snapshot. 
See the <b>Keyboard</b> tab in this window for a complete shortcut list.<br><br>
Double clicks automates single click actions: A left button double click aligns 
the closer axis with the camera (if close enough). A middle button double click 
fits the zoom of the camera and the right button re-centers the scene.<br><br>
A left button double click while holding right button pressed defines the camera 
<i>Revolve Around Point</i>.
See the <b>Mouse</b> tab and the documentation web pages for details.<br><br>
Press <b>Escape</b> to exit the viewer."""
class Viewer(QGLViewer):
    def __init__(self,parent = None):
    def draw(self):
    def init(self):
    def helpString(self):
        return helpstr
def main():
    qapp = QApplication([])
    viewer = Viewer()
if __name__ == '__main__':


Back to top
examples.1181305461.txt.gz ยท Last modified: 2007/06/08 14:24 by admin
Valid CSS Driven by DokuWiki Valid XHTML 1.0