views:

1390

answers:

4

I'm interested in playing around with OpenGL in Python. I've used OpenGL in C++ and Objective-C, but I don't have much experience in Python. I'm wondering if there's a good tutorial that works in Snow Leopard. I'd prefer to stay in 64-bit mode if possible, since I've heard 32-bit programs require loading a lot of extra 32-bit libraries.

I've already tried a PyOpenGL/wxPython tutorial. When I ran the code, it crashed with this message:

ImportError: /System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/wx-2.8-mac-unicode/wx/_core_.so: no appropriate 64-bit architecture (see "man python" for running in 32-bit mode)

It looks like there's a bug in wxPython that prevents it from working on a 64-bit system.

I also looked at Pyglet, but they have a similar issue. They provide a work-around (setting Python to 32-bit mode), but it doesn't look like they're going to fix it.

Finally, I looked at PyGLUT, but I think it's only for Windows.

Are there any other libraries that would let me access OpenGL and draw on the screen? Again, I'd prefer to stay in 64-bit mode, but if nothing works, I'll switch to 32-bit and try wxPython or Pyglet again.


Edit: I've also tried PyGame. It depends on SDL which is broken in SL. I thought about trying to use Cocoa through PyObjc, but the Xcode Python application templates have been removed.

A: 

You could try pygame. Pygame is a python wrapper around SDL. According to their website they have Max OS X binaries. Here is a simple example of using pygame with OpenGL. Once you are able to create the window and handle events most OpenGL programming is just like it would be in C or C++, but with some added python goodness. For OpenGL a great tutorial is NeHe.

Jon
I can't actually get PyGame to install. easy_install throws up a bunch of errors when compiling _numericsurfarray.c because SDL.h is missing. SDL 1.2 has a dependency on QuickDraw (http://bugzilla.libsdl.org/show_bug.cgi?id=581), which is no longer in Snow Leopard, so it will probably never work.
Jay Conrod
I also tried the binary installer. It says it requires "System Python 2.6" to install, which is weird because SL comes with 2.6.1.
Jay Conrod
+1  A: 

There's probably no good reason to avoid 32-bit mode. Unless your Python programs need to larger address space, of course.

Mark Bessey
Don't 32-bit programs need to load the whole 32-bit stack in SL? It seems like this would waste a lot of resources. You're probably right though; this doesn't need to be high-performance code.
Jay Conrod
You're quite likely to have other 32-bit processes running, so the overhead will be minimal.
Mark Bessey
There's one great reason: portability. you can't assume your users will be setting global system var and what-have-you to get your app running.
dan mackinlay
A: 

Also when programing with OpenGL in python remember that Python datastructures can be rather slow when it comes to requirements for 3D graphics. PyGL developers for example recommend using ctypes for operations that concern graphics, since that way you can get enough performance for some complicated geometry with bareable FPS.

Mavrik
+4  A: 

I've used PyOpenGL 3.0.0 quite successfully on Snow Leopard. It uses ctypes, so it should be making 64-bit calls if those libraries are available (and Snow Leopard's Python includes a 64-bit version). I haven't used the wxPython stuff with PyOpenGL so that's where you might be running into problems, but PyOpenGL also includes GLUT, which both run fine.

Adam K. Johnson
I didn't know PyOpenGL included GLUT. I assumed PyGLUT was the only GLUT interface available. In any case, I wrote a quick program using just PyOpenGL, and it works great.
Jay Conrod