3-D Programming with Python
Texturing mapping is the technique of taking image data, like a photograph, and “gluing” it to a polygon. Using textures requires converting the external texture images into one of the low-level internal formats supported by OpenGL. While the code required for setting textures in Python does not differ much from normal OpenGL code, Python does simplify the process of loading and manipulating texture image files.
The Python standard library includes rgbimg, a module for reading SGI imglib(.rgb) files. While this may seem like an obscure format, its simplicity allows its inclusion in Python's standard library without causing too much bloat. Using the GIMP or ImageMagick, you can convert images from formats like PNG, JPEG or TIFF to SGI imglib. The command rgbimg.longimagedata(file) will read and decode the specified SGI imglib formatted file and return it as a binary string of four-byte RGBA pixels. This data can be passed to OpenGL functions like glTexImage2D, using the format parameter GL_RGBA and the data type GL_UNSIGNED_BYTE.
Another useful module in the Python standard library is imageop. This module includes functions for cropping, scaling and grayscale conversions for images. The imageop functions operate on data in the same GL_RGBA/GL_UNSIGNED_BYTE format as the data returned from rgbimg.longimagedata().
In addition to wrapping the core libraries and toolkits, PyOpenGL also includes a number of utility functions to perform high-level tasks. Have you ever wanted to grab a still image of an OpenGL scene? You always can use programs that support screen capture, such as xv or The GIMP, but what if you want to grab a still at a specific point in time? Taking screenshots manually won't work if the program needs to run without user control, like a CGI script. You also can't grab a dozen stills a second manually to create a movie. PyOpenGL has a couple helper functions for automatically grabbing scene shots in various formats.
Listing 3 is an adaptation of the previous program that saves a PostScript image of the scene to disk, then exits. You can take a look at the image that was saved in Figure 1.
Listing 3. Saving a PostScript Image, Then Exiting

Figure 1. Results from Listing 3
The scene is saved using the command
openglutil.glSaveEPS('ex3.eps', 240, 240)
The first argument is the name of the file to save to. The second is the width in pixels to capture, and the third is the height. Using the same syntax with the glSavePPM() command will save an image of the scene in the portable pixmap file format. Additionally, if you have compiled PyOpenGL with TIFF support, the command glSaveTIFF() is available for saving scene shots in the TIFF format.
PyOpenGL also provides a convenience wrapper for OpenGL's object selection or “picking” mechanism. The selection mode of operation in OpenGL automatically tells you which objects fall within a given region of the view screen. This means you can pass the selection mechanism to a point on the screen where a mouse click occurred, and it will tell you what object was clicked on.
Here are the basic steps for setting up the selection mechanism in PyOpenGL:
Write a method or function that draws each object in the scene wrapped in between a call to glPushName() and glPopName(). Pass a different integer as an argument to glPushName() for each independent object in the scene. OpenGL will use this value to indicate which objects were selected.
Set up the event handler for mouse clicks. The way this works depends on the toolkit you are using. In Tkinter, mouse-click event handlers are set up by passing a method or function reference to the bind() method.
Once a mouse click has occurred, pass the mouse x and y coordinates, along with a reference to the method or function created in part one, to the function OpenGL.GL.glSelectWithCallback(). This function will return a list of tuples of the form (near, far, names) where near and far represent integer depth values, and names is a tuple of the names passed in glPushName() for the selected objects. If no objects were selected, an empty tuple is returned.
Listing 4 demonstrates use of the selection mechanism in PyOpenGL. This demo draws a cube and a sphere on the screen. Experiment with holding down the Ctrl key and pressing the left mouse button with the pointer in different places.
Listing 4. The Selection Mechanism in PyOpenGL

Figure 2. Results from Listing 4

The fog.py Demo Included with PyOpenGL

A Simple Scene with Lighting and Textures Rendered Using PyOpenGL

A 3DStudio Model Rendered Using PyOpenGL
The selection mechanism is the simplest way to perform this task, but it is by no means the only way. Another technique is to render the objects to a back buffer that OpenGL does not send to an output device. To do this, render each object using a different color. Once done, the back buffer should contain the 2-D rendering of the scene. By examining the color at a particular point you can determine which object was drawn in that region of the screen. This back buffer is called the feedback buffer in OpenGL.
Yet another method for object picking is to do the intersection testing by hand. This means you would have to project a ray from the view screen and test each object in the scene for intersection. Once you have found a list of intersected objects, you then must sort by depth values to see which was closest to the view screen. While this may offer more control over the process, it is an arduous task and is difficult to do efficiently in Python.
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Sponsored by AMD
If you already use virtualized infrastructure, you are well on your way to leveraging the power of the cloud. Virtualization offers the promise of limitless resources, but how do you manage that scalability when your DevOps team doesn’t scale? In today’s hypercompetitive markets, fast results can make a difference between leading the pack vs. obsolescence. Organizations need more benefits from cloud computing than just raw resources. They need agility, flexibility, convenience, ROI, and control.
Stackato private Platform-as-a-Service technology from ActiveState extends your private cloud infrastructure by creating a private PaaS to provide on-demand availability, flexibility, control, and ultimately, faster time-to-market for your enterprise.
Sponsored by ActiveState
| Non-Linux FOSS: libnotify, OS X Style | Jun 18, 2013 |
| Containers—Not Virtual Machines—Are the Future Cloud | Jun 17, 2013 |
| Lock-Free Multi-Producer Multi-Consumer Queue on Ring Buffer | Jun 12, 2013 |
| Weechat, Irssi's Little Brother | Jun 11, 2013 |
| One Tail Just Isn't Enough | Jun 07, 2013 |
| Introduction to MapReduce with Hadoop on Linux | Jun 05, 2013 |
- Containers—Not Virtual Machines—Are the Future Cloud
- Non-Linux FOSS: libnotify, OS X Style
- Lock-Free Multi-Producer Multi-Consumer Queue on Ring Buffer
- Linux Systems Administrator
- Validate an E-Mail Address with PHP, the Right Way
- RSS Feeds
- Introduction to MapReduce with Hadoop on Linux
- Weechat, Irssi's Little Brother
- New Products
- Developer Poll
- Reply to comment | Linux Journal
1 hour 50 min ago - Reply to comment | Linux Journal
2 hours 35 min ago - Didn't read
2 hours 46 min ago - Reply to comment | Linux Journal
2 hours 51 min ago - Poul-Henning Kamp: welcome to
5 hours 1 min ago - This has already been done
5 hours 2 min ago - Reply to comment | Linux Journal
5 hours 47 min ago - Welcome to 1998
6 hours 36 min ago - notifier shortcomings
6 hours 59 min ago - heroku?
8 hours 36 min ago
Featured Jobs
| Linux Systems Administrator | Houston and Austin, Texas | Host Gator |
| Senior Perl Developer | Austin, Texas | Host Gator |
| Technical Support Rep | Houston and Austin, Texas | Host Gator |
| UX Designer | Austin, Texas | Host Gator |
| Web & UI Developer (JavaScript & j Query) | Austin, Texas | Host Gator |
Free Webinar: Hadoop
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Some of key questions to be discussed are:
- What is the “typical” Hadoop cluster and what should be installed on the different machine types?
- Why should you consider the typical workload patterns when making your hardware decisions?
- Are all microservers created equal for Hadoop deployments?
- How do I plan for expansion if I require more compute, memory, storage or networking?




Comments
Solution for Python 2.5.2
Just Download TOGL 2.0 and uncompress it on TCL sub directory in Python Installation directory.
now it included in Python TK TCL auto_path and can be used in TKinter
i tested it with sample code.
i using XP , Python 2.5.2
togl
You say :
While GLUT is suitable for most small OpenGL applications, it still requires a fair amount of work to implement functionality that is often desirable when testing, such as mouse control for zooming, panning and rotation. Togl is a Tkinter widget that automatically provides these features as well as default lighting.
but Mike C. Fletcher said:
http://coding.derkeiler.com/Archive/Python/comp.lang.python/2003-11/3768...
Togl refuses to compile with the version of Tk distributed with Python 2.3 and above[...] and so it's being dropped from PyOpenGL. You can rebuild PyOpenGL 2.0.1 with Togl support on Unix, but unless you really need to run old scripts which used it, it's probably not worth the effort (of setting the flag to true).
In theory, if you can compile (or find compiled) Togl for Tk 8.4 (and then install it in the Python Tk instance), it should run fine. I, however, have burned far too much PyOpenGL development time on it (given that Tk is hardly the cutting edge in GUIs these days), so I'm not likely to work on it any more.
Lol
togl !!
Most people use python 2.3 , 2.4 or 2.5
I use pyhon 2.2 with PyOpenGL ...