Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python

PyOpenGL Tutorial?

 

 

Python python RSS feed   Index | Next | Previous | View Threaded


clay at lakeserv

Jul 23, 2008, 1:07 PM

Post #1 of 4 (11060 views)
Permalink
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

--
http://mail.python.org/mailman/listinfo/python-list


arsyed at gmail

Jul 23, 2008, 10:22 PM

Post #2 of 4 (11016 views)
Permalink
Re: PyOpenGL Tutorial? [In reply to]

On Wed, Jul 23, 2008 at 4:07 PM, Clay Hobbs <clay [at] lakeserv> wrote:
> 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
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>


Showmedo recently put up a tutorial screencast of using wx, opengl,
python to build a molecular viewer:

http://showmedo.com/videos/series?name=vXJsRwlBX

Also, see:

http://www.siafoo.net/browse?keyword_id=245
--
http://mail.python.org/mailman/listinfo/python-list


mcfletch at vrplumber

Jul 25, 2008, 4:22 AM

Post #3 of 4 (10988 views)
Permalink
Re: PyOpenGL Tutorial? [In reply to]

arsyed wrote:
...
> Also, see:
>
> http://www.siafoo.net/browse?keyword_id=245
>
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 for them any more.

There's also tutorials that are not wxPython specific on the PyOpenGL
documentation page.

HTH,
Mike

--
________________________________________________
Mike C. Fletcher
Designer, VR Plumber, Coder
http://www.vrplumber.com
http://blog.vrplumber.com

--
http://mail.python.org/mailman/listinfo/python-list


sturlamolden at yahoo

Jul 25, 2008, 7:24 AM

Post #4 of 4 (10999 views)
Permalink
Re: PyOpenGL Tutorial? [In reply to]

On Jul 23, 10:07 pm, Clay Hobbs <c...@lakeserv.net> wrote:
> 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






--
http://mail.python.org/mailman/listinfo/python-list

Python python RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.