Hi Aiden, 

Yes, compiling a shader works fine in Python 3. You can check out my shader 
branch here:
https://bitbucket.org/treehousegames/pyglet/src/196e5086a04cbedd4bab9d47c8ae8361f7040d23/?at=shader_class
Also, If you look in the root of that directory, you will see a lab.py file 
with an example of creating an OpenGL 3.3 context and some dead simple GLSL 
3.3 vert/frag shaders. It works just fine with an OpenGL 4.x context and 
shaders as well. If you are using an OpenGL core profile, you MUST override 
the window.on_resize() method as shown in the lab.py file, otherwise your 
program will crash due to some legacy OpenGL code being called. 

The shader library itself is located inside the graphics module, at 
pyglet/graphics/shader.py. 
You can either use it as a context manager, using the "with" statement 
(like you were asking about), or you can use it's .stop_progam() and 
.use_program() methods. 

It works fine as it is, but I'm really looking for feedback on it. I'd 
appreciate it if you could let me know how it works out for you, or why it 
doesn't. 

-Ben


On Wednesday, April 20, 2016 at 1:12:09 PM UTC+9, Aiden Ward wrote:
>
> i need help getting shaders to work in pyglet.
>
> did you get this working in python 3?
>
> shader_program = Program(vertex_source, fragment_source)
>
> with shader_program:
>     do_stuff()
>
> On Tuesday, February 16, 2016 at 2:52:34 PM UTC, Benjamin Moran wrote:
>>
>> It seems like there is a lot of demand for this! 
>>
>> I think there are a lot of small implementation details to think about, 
>> to make it easy for users. For example:
>>
>>    - Dealing with the Window.on_resize behavior if shaders are used.
>>    - Should checking be done on OpenGL context versions before compiling 
>>    a shader? Maybe check against the the shader source's "#version" string 
>> if 
>>    it exists?
>>    - Debug: should the shader class have it's own debug flag, or rely on 
>>    the pyglet OpenGL debug flag? Does it make sense to have it's own as GLSL 
>>    is it's own thing? 
>>    - Needs to be Python2.7/3 compatible. This should only require a few 
>>    small things, such as confirming the shader source is a byte string.
>>    
>>
>> My current code has bind and unbind methods, but also has __enter__ and 
>> __exit__ methods which just call bind and unbind. I like using it with a 
>> "with" context: 
>> shader_program = Program(vertex_source, fragment_source)
>>
>> with shader_program:
>>     do_stuff()
>>
>>
>>
>>
>> On Tuesday, February 16, 2016 at 11:16:20 PM UTC+9, Paulo Martins wrote:
>>>
>>> x2 I love the idea.
>>>
>>> terça-feira, 16 de Fevereiro de 2016 às 00:53:46 UTC, Benjamin Moran 
>>> escreveu:
>>>>
>>>> Hi guys, 
>>>>
>>>> How would everyone feel about adding a simple shader Class to the 
>>>> graphics module? There have been a few go-to examples out there, such as 
>>>> Tristan McDonald's popular one here: 
>>>> https://swiftcoder.wordpress.com/2008/12/19/simple-glsl-wrapper-for-pyglet/
>>>> And Leonhard Vogt's framebuffer code that includes shaders here:
>>>>
>>>> https://leovt.wordpress.com/2015/10/04/render-to-texture-with-python-3-and-pyglet/
>>>> https://github.com/leovt/leovt/blob/master/framebuffer.py
>>>>
>>>> The reason I would like to see it included is because of the ctypes 
>>>> magic being a bit of a blocker for new users. A simple class could handle 
>>>> this for the users, and allow them to easily try more modern contexts with 
>>>> pyglet. 
>>>>
>>>> If I wrote this code, would it be accepted? I'm thinking a simple 
>>>> class, plus basic example code. (Speaking of which, many of those examples 
>>>> need to be updated!)
>>>>
>>>> -Ben
>>>>
>>>>

-- 
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.

Reply via email to