Differences between revisions 1 and 2
Revision 1 as of 2006-09-20 17:40:45
Size: 3289
Comment:
Revision 2 as of 2006-09-21 04:59:21
Size: 3411
Editor: RichardJones
Comment:
Deletions are marked like this. Additions are marked like this.
Line 40: Line 40:
PyOpenGL is a large Python package that wraps most (perhaps all?) of PyOpenGL is a large Python package that wraps most (up to version 1.2) of
Line 43: Line 43:
from having to learn the details of OpenGL. from having to learn the details of OpenGL. It does abstract the API so you
call glColor in place of glColor3b, glColor3d, glColor3f, glColor3i, glColor3s, ...

OpenGL is a well-known library for displaying 2D and 3D graphics.

On a Linux system, OpenGL is divided into a number of distinct libraries:

  • libGL.so is the core implementation of OpenGL. If you're using a fancy 3D-accelerated card, this library might be a closed-source version provided by the card vendor.
  • libGLU.so is the GL Utility library, providing a number of convenience functions built on top of libGL. For example, libGL provides support for evaluating polynomials; libGLU includes a function that constructs polynomials for commonly-used shapes such as spheres.
  • GLX is the OpenGL/X11 interface; in theory you could encapsulate the OpenGL API in any windowing protocol, but in practice Linux users are only interested in X11 support. GLX doesn't seem to be a library in the formal sense; there doesn't seem to be a libGLX.so lying around, so I assume it's included in either GLU or the core GL.
  • GLUT is yet another utility library. OpenGL only defines how to draw things on screen, not how to interact with them. For example, you would have to write your own X11 to open an X11 window and to handle the 'close' event when the user tries to close the window. GLUT fills this gap by providing support for windows that can be opened/closed, the ability to render fonts, and simple pop-up menus, but it's not a full-featured UI toolkit like Qt; there are no dialog boxes, text entry fields, or anything more advanced than menus. GLUT also includes a few oddball functions that do things such as render spheres or teapots.

Because there are so many libraries, programming OpenGL is kind of a mess; one program may use constants and functions from several of the above libraries.

PyOpenGL

PyOpenGL is a large Python package that wraps most (up to version 1.2) of the OpenGL API. However, it doesn't try to clean up the API and present a more Pythonic interface, so it won't save you (or, more importantly, me) from having to learn the details of OpenGL. It does abstract the API so you call glColor in place of glColor3b, glColor3d, glColor3f, glColor3i, glColor3s, ...

Here's the skeleton for a program that displays something:

import sys
from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *

# The display() method does all the work; it has to call the appropriate
# OpenGL functions to actually display something.
def display():
    # Clear the color and depth buffers
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

    # ... render stuff in here ...
    # It will go to an off-screen frame buffer.

    # Copy the off-screen buffer to the screen.
    glutSwapBuffers()

glutInit(sys.argv)

# Create a double-buffer RGBA window.   (Single-buffering is possible.
# So is creating an index-mode window.)
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH)

# Create a window, setting its title
glutCreateWindow('interactive')

# Set the display callback.  You can set other callbacks for keyboard and
# mouse events.
glutDisplayFunc(display)

# Run the GLUT main loop until the user closes the window.
glutMainLoop()

OpenGL (last edited 2008-11-15 14:00:44 by localhost)

Unable to edit the page? See the FrontPage for instructions.