Ok, I've answered my own question.
The first step is to create and link the shader.
Using the existing wrapper this is simple:
self.shader = Shader(
vert = Data.vert_shader,
frag = Data.frag_shader
)
Then we query OGL for an attribute index
self.attrib = glGetAttribLocation(
self.shader.handle,
"index"
)
Then when creating the vertex list, create a string that uses the queried
for attribute value
# set the attribute index
attrib_type = "%ig1f" % (self.attrib)
self.vertex_list = pyglet.graphics.vertex_list(
<snip>
(attrib_type, attribs),
)
In the vertex shader you need an attribute with the name you queried for.
In this case:
attribute float index;
You can test it by this as a varying value to the fragment shader and
rendering it as the colour:
vertex shader:
varying vec4 debug;
void main()
{
<snip>
debug = vec4( index, index, index, 1.0 );
}
fragment shader:
varying vec4 debug;
void main()
{
// divide by the number of vertices
gl_FragColor = debug / vec4( 1000, 1000, 1000, 1.0 );
}
BAM!
Hope that helps someone in the future.
Cheers,
Adam
On Wednesday, September 12, 2012 5:59:12 PM UTC+10, Adam Griffiths wrote:
>
> I'm trying to pass vertex attributes to a GLSL vertex shader.
>
> I've created the following vertex_list:
> self.vertex_list = pyglet.graphics.vertex_list(
> num_verts,
> ('v3f/static', verts),
> ('t2f/static', tcs),
> ('0g1f', attribs),
> )
>
> I've also put this in my GLSL vertex shader:
>
> attribute float index;
>
>
> But I'm unsure how to bind the attribute array to the GLSL input?
>
> The GL spec says I should call glGetAttribLocationARB which receives the
> attribute name.
> Should I call this, then use the returned value as the first value of the
> attribute?
> Ie. "Xg1f" instead of "0g1f"
>
>
> I'm using the GLSL shader wrapper from here incase that matters:
> http://swiftcoder.wordpress.com/2008/12/19/simple-glsl-wrapper-for-pyglet/
>
>
> Cheers,
> Adam
>
--
You received this message because you are subscribed to the Google Groups
"pyglet-users" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/pyglet-users/-/rR-EQtzwkU8J.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/pyglet-users?hl=en.