views:

1175

answers:

7
+1  Q: 

OpenGl with Python

I am currently in a course that is using OpenGL and I have been using C for all the programs so far. I have Python installed on Fedora as well as OpenGL however the minute I call an OpenGL command in my Python code I get a segmentation fault. I have no idea why this is.

Just to avoid the "just use C" comments heres why I want to use Python.

There are a couple reasons I am wanting to switch from C to Python, but the main one is because we are about to start writing a raytracer and I would like to use classes to make it easier on me. Since I hate classes in C++ and structs in C seems a little crazy, I thought I would give Python a try at it. I have also been looking for a reason to use Python again as it has been a while.

Thanks for any help.

+1  A: 

What OpenGL library are you using? What windowing library? What version of Python?

Most likely cause I can think of is that your windowing library (SDL or whatever you're using) isn't initializing OpenGL before you start calling into it.

Cody Brocious
I am using Python 5.3.1, PyOpenGL 3.0.0-0.8, freeglut 2.4.0-14
corymathews
5.3.1? No you're not.
Peter Hosey
2.5.1 lol sry way off
corymathews
A: 

We have neither ideas about random segmentation faults. There is not enough information. What python libraries are you using for opengl? How do you use them? Can you show us your code? It's probably something trivial but my god -skill ends up to telling me just and only that.

Raytracer in python? I'd prefer just doing that in C with those structs. But then, I'm assuming you aren't going to do a realtime raytracer so that may be ok.

Cheery
+3  A: 

You may also want to consider using Pyglet instead of PyOpenGL. It's a ctypes-wrapper around the native OpenGL libs on the local platform, along with windowing support (should handle most of the stuff you want to use GLUT for.) The pyglet-users list is pretty active and very helpful.

technomalogical
A: 

Perhaps you are calling an OpenGL function that requires an active OpenGL context, without having one? That shouldn't necessarily crash, but I guess it might. How to set up such a context depends on the platform, and it's been a while since I used GL from Python (and when I did, I also used GTK+ which complicates matters).

unwind
A: 

http://pyopengl.sourceforge.net/

:)

plan9assembler
+1  A: 

Well, I don't know if these are the libs the original poster are using but I saw identical issues in a pet project I'm working on (Graphics Engine using C++ and Python) using PyOpenGL.

PyOpenGL didn't correctly pick up the rendering context if it was created after the python script had been loaded (I was loading the script first, then calling Python methods in it from my C++ code).

The problem doesn't appear if you initialize the display and create the OpenGL rendering context before loading the Python script.

Adam Luchjenbroers
A: 

Scripts never cause segmentation faults. But first see if your kernel and kmod video driver working property ... Extension modules can cause "segmentation fault".

Catalin Festila