Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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, here is 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.

like image 654
corymathews Avatar asked Oct 28 '08 02:10

corymathews


People also ask

Can I use OpenGL with Python?

First off, PyOpenGL is just some Python bindings (some Python code that acts like a sort of wrapper around native code), so you can manipulate OpenGL within the context of Python. OpenGL is a cross-language API, so you can take your knowledge of OpenGL to other languages.

Does pygame use OpenGL?

Pygame doesn't even have OpenGL bindings; you'd need to use PyOpenGL with it. If your goal is to learn OpenGL, my suggestion would be to use PyOpenGL, with Pygame. The API is closer to actual OpenGL.

What is pygame OpenGL?

PyOpenGL is the standardized library used as a bridge between Python and the OpenGL APIs, and PyGame is a standardized library used for making games in Python. It offers built-in handy graphical and audio libraries and we'll be using it to render the result more easily at the end of the article.


2 Answers

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.

like image 185
technomalogical Avatar answered Sep 23 '22 13:09

technomalogical


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.

like image 34
Adam Luchjenbroers Avatar answered Sep 20 '22 13:09

Adam Luchjenbroers