3-D Programming with Python
Now that you have seen how to write simple OpenGL programs, you are probably wondering if Python can scale up to the demands of more advanced 3-D applications. While the performance of a PyOpenGL program generally lags behind that of its C or C++ counterpart, optimization techniques can narrow the gap considerably.
The main strategy in improving execution speed is to reduce the amount of time spent within the Python interpreter by moving expensive operations into native code. One means of accomplishing this is to rewrite sluggish parts of the program in a fast, natively compiled language like C or C++. Implementing these compiled portions of the program as Python extension modules allows the remaining interpreted Python code to access their functionality. While this approach certainly has potential for speeding things up, it lacks the simplicity of a pure Python solution. It also requires you understand how to write Python extension modules in a language that compiles to native code. Besides, if you wanted to do it in C, you wouldn't have started messing around with Python in the first place!
OpenGL display lists provide a way to move operations into native code without any of the headaches associated with the former approach of writing extension modules. Display lists allow OpenGL programs to cache a set of commands further down in the rendering pipeline. In some environments, OpenGL even can store display lists on the graphics card itself, far away from the bottleneck of the Python interpreter.
The glGenLists() command creates an array of empty display lists. It takes a single integer argument, the number of display lists, to generate. It returns the number of lists that were successfully created. Wrapping a set of OpenGL operations with the commands glNewList() and glEndList() fills a specified display list. Once stored, subsequent invocations of that set of operations requires only a single command, glCallList(). The syntax for using display lists in PyOpenGL is pretty much the same as in OpenGL with C.
We have just begun to scratch the surface of OpenGL programming techniques in Python. For more information, make sure to check out the documentation that comes with PyOpenGL or on-line at pyopengl.sourceforge.net/documentation/index.html.
One Click, Universal Protection: Implementing Centralized Security Policies on Linux Systems
Join editor Bill Childers and Bit9's Paul Riegle on April 27 at 12pm Central to learn how to keep your Linux systems secure.
Free to Linux Journal readers.Register Now!
- Cluetrain at Fifteen
- Embedding Python in Your C Programs
- Getting Good Vibrations with Linux
- [<Megashare>] Watch Mrs Brown's Boys Movie Online Full Movie HD 2014
- New Products
- Customizing Vim
- Memory Ordering in Modern Microprocessors, Part I
- Security Hardening with Ansible
- RSS Feeds
- Tech Tip: Really Simple HTTP Server with Python