Vertex and fragment shaders - modern opengl tutorials for pyglet?

832 views
Skip to first unread message

viper

unread,
Sep 3, 2012, 6:30:18 AM9/3/12
to pyglet...@googlegroups.com
I'd tried some time ago to learn opengl with pyglet but wound up being way out of my depth. There are a number of good, modern tutorials for c/c++ that teach opengl, such as open.gl and https://github.com/progschj/OpenGL-Examples, so I turned to c++ instead.

I do however, prefer to work with python.

Are there any such tutorials for pyglet? For example, does anyone have or know of some basic tutorials for python 3 pyglet that show how to use vertex and fragment shaders without requiring another library or addon and that also do not use deprecated functionality of opengl?

Maybe this is a big ask but I see a new alpha of pyglet has been released and I have renewed interest.

Tristam MacDonald

unread,
Sep 3, 2012, 8:17:07 AM9/3/12
to pyglet...@googlegroups.com
Pyglet doesn't provide out-of-the-box convenience classes for working with Shaders, so you'll probably want to use a 3rd-party GLSL wrapper to handle that part (unless you feel like rolling your own).

If you are interested, I published a light-weight set of classes and a simple demonstration on my blog a while back: http://swiftcoder.wordpress.com/2008/12/20/conways-game-of-life-in-glslpyglet/

I don't know of any pyglet-specific tutorials, off the top of my head, but someone may have some stashed away.
--
Tristam MacDonald
Software Development Engineer, Amazon.com

viper

unread,
Sep 3, 2012, 11:11:57 PM9/3/12
to pyglet...@googlegroups.com
Thanks, I had seen your website and your GLSL wrapper in previous googling. However I could not get it to work.
I tried it again with renewed enthusiasm but I'm a bit stuck.

I've converted it from 2to3, both the shader and the game of life example. I then converted line 17 of game of life to an integer for the window dimensions and added ctypes import to the shader wrapper.
Now this line in the shader wrapper: src = (c_char_p * count)(*strings)
is causing this error: TypeError: bytes or integer address expected instead of str instance
I think python 3 may not like this. I googled around and got reference to making something a byte perhaps, but I'm clearly out of my depth here.
If you have any suggestions I'd be pleased to try them out.

Matt Ebb

unread,
Sep 3, 2012, 11:43:53 PM9/3/12
to pyglet...@googlegroups.com
On Tue, Sep 4, 2012 at 1:11 PM, viper <vipe...@gmail.com> wrote:
> Now this line in the shader wrapper: src = (c_char_p * count)(*strings)
> is causing this error: TypeError: bytes or integer address expected instead
> of str instance
> I think python 3 may not like this. I googled around and got reference to
> making something a byte perhaps, but I'm clearly out of my depth here.
> If you have any suggestions I'd be pleased to try them out.

Probably because python 3 strings are unicode by default. You can try
str.encode() or bytes() to convert it to bytes?

http://docs.python.org/release/3.0.1/whatsnew/3.0.html#text-vs-data-instead-of-unicode-vs-8-bit
Reply all
Reply to author
Forward
0 new messages