473,401 Members | 2,127 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

PyOpenGL Tutorial?

I need a tutorial for PyOpenGL (specifically, to be used with wxPython).
I searched with Google and didn't find one. Does anybody know where one
is?

-- Ratfink

Jul 23 '08 #1
1 6703
On Jul 23, 10:07*pm, Clay Hobbs <c...@lakeserv.netwrote:
I need a tutorial for PyOpenGL (specifically, to be used with wxPython).
I searched with Google and didn't find one. *Does anybody know where one
is?
PyOpenGL is just a wrapper for OpenGL. The API is identical. Do you
need an OpenGL tutorial?

As for wxPython, you just subclass wxGLCanvas. Call the method
SetCurrent() before you call OpenGL (e.g. through PyOpenGL) and
SwapBuffers() when you are done. See the wxWidgets reference.

Personally I think PyOpenGL is a slow beast. It is not just a thin
wrapper over OpenGL, but bloated with sanity checks, exception
handling, etc (look at the code, it is pure Python and easy to read).
I prefer to put all calls to OpenGL in a C DLL, and call that with
ctypes. If I make repeated calls to functions like glVertex3f, I want
them to to be fast, thus C is indicated over Python. And if all I do
in C is to make calls into OpenGL, there is no real advantage to using
Python here - the Python code would look almost exactly the same, but
would be slower by several orders of magnitude. By the way, I still
use wxGLCanvas from wxPython to set things up. The ctypes call into my
C DLL is called between SetCurrent() and SwapBuffers().

If you want a pure Python solution, you will need to use display
lists, vertex arrays (with NumPy) or vertex buffers (if your graphics
card supports it) to get acceptable performance.

Here is a short tutorial:

import wx
import wx.glcanvas
import ctypes

glrender = ctypes.pydll.glrender.render # use ctypes.cdll to call with
GIL released
glrender.argtypes = (ctypes.c_int, ctypes.c_int,)
glrender.restype = None

class MyCanvas(wx.glcanvas.GLCanvas):

def __init__(self, parent):
attribList = (wx.glcanvas.WX_GL_DOUBLEBUFFER,
wx.glcanvas.WX_GL_RGBA, 0)
wx.glcanvas.GLCanvas.__init__(self, parent, -1, attribList =
attribList)
self.context = wx.glcanvas.GLContext(self)
self.Bind(wx.EVT_SIZE, self.OnSize)
self.Bind(wx.EVT_PAINT, self.OnPaint)

def OnSize(self, evt):
w,h = self.GetClientSize()
self.w = w
self.h = h
dc = wx.ClientDC(self)
self.Render(dc)

def OnPaint(self, evt):
dc = wx.PaintDC(self)
self.Render(dc)

def Render(self, dc):
self.SetCurrent()
glrender(self.w, self.h)
self.SwapBuffers()

And then in glrender.c, put the following:
#include <GL\gl.h>
#include <GL\glu.h>
#include <GL\glext.h>

__declspec(dllexport)
void render(int w, int h)
{
/* calls to OpenGL goes here */
return;
}

And for Python 2.5.x on Windows, compile with:

gcc -O2 -o glrender.dll -shared -lopengl -lmsvcr71 glrender.c


Jul 25 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Erik Max Francis | last post by:
I was interesting in adding selection and hit testing to ZOE, and was looking at the PyOpenGL wrappers' handling of selection and picking. I see glSelectBuffer to specify the size of the buffer,...
2
by: matt.walsh | last post by:
Hey I'm a programmer looking to port some of my opengl ...although limited into a python app I've made... I'd like to know where to find any python/opengl source or a tutorial etc.. whatever I'd...
1
by: Marco | last post by:
I must use text in Opengl, Python This text is for architecture design then I need to use AutoCad fonts (extension .shx). I have two troubles: I don't find a guide, a good program, something...
5
by: Sébastien Ramage | last post by:
Bonjour à tous, Dans la folie j'ai installé le nouveau python, impatient de voir les nouveautés mais je pense que j'ai été un peu rapide car j'ai voulu utiliser pyOpenGL et là problème il...
0
by: sweetmelon | last post by:
(I'm a newbie in Python and pyOpenGL.) Environment: WinXP SP2 Python ver. 2.5 WingIDE easy_install is installed PIL, pyNum is installed Download PyOpenGL-3.0.0a5-py2.5.egg run: easy_install...
0
by: shirish | last post by:
Hi all, Is it possible to have Python+Pygame+PyOpenGL in one compact package so people can play the games released at pyweek.org . I have been having a hard time getting the whole thing on windows...
2
by: seb.haase | last post by:
Hi, I am distributing a package with a precompiled collection of modules and packages useful for Python based medical/biological/astronomical image analysis and algorithm development. (Codename:...
0
by: Colin J. Williams | last post by:
I have just installed PyOpenGL and get a series of warning messages: Best match: PyOpenGL 3.0.0b3 Downloading...
0
by: Mike C. Fletcher | last post by:
arsyed wrote: .... But note regarding the second tutorial there that the PyOpenGL 3.x *does* supply wrappers for most publicly known extensions, so you shouldn't have to create your own wrappers...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.