Skip to content

Commit e19c3ed

Browse files
Fix rendering textured quad in legacy.
Don't use location=. Remove generic attribute since we're using FF. Set gl_TexCoord[0] to gl_MultiTexCoord0. Bind the sampler to texture unit 0.
1 parent c986b2a commit e19c3ed

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

pygly/examples/renderable_textured_quad.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -144,18 +144,13 @@ class LegacyQuad( object ):
144144
vertex_shader = textwrap.dedent( """
145145
#version 120
146146
147-
// input
148-
attribute vec2 in_uv;
149-
150-
// shared
151-
varying vec2 ex_uv;
152-
153147
void main(void)
154148
{
155149
// apply projection and model view matrix to vertex
156150
gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * gl_Vertex;
157151
158-
ex_uv = in_uv;
152+
// select the texture coordinate to use
153+
gl_TexCoord[0] = gl_MultiTexCoord0;
159154
}
160155
""" )
161156

@@ -165,13 +160,10 @@ class LegacyQuad( object ):
165160
// input
166161
uniform sampler2D in_diffuse_texture;
167162
168-
// shared
169-
varying vec2 ex_uv;
170-
171163
void main(void)
172164
{
173165
// set colour of each fragment
174-
gl_FragColor = texture2D( in_diffuse_texture, ex_uv );;
166+
gl_FragColor = texture2D( in_diffuse_texture, gl_TexCoord[0].st );
175167
}
176168
""" )
177169

@@ -183,6 +175,8 @@ def __init__( self ):
183175

184176
self.use_shaders = True
185177

178+
GL.glEnable(GL.GL_TEXTURE_2D)
179+
186180
# create our shader
187181
self.shader = ShaderProgram(
188182
VertexShader( self.vertex_shader ),
@@ -200,22 +194,21 @@ def __init__( self ):
200194
self.buffer_attributes[ 'position' ] = VertexAttribute.from_dtype(
201195
self.buffer,
202196
vertices.dtype,
203-
'position',
204-
location = self.shader.attributes[ 'in_position' ]
197+
'position'
205198
)
206199

207200
self.buffer_attributes[ 'uv' ] = TextureCoordAttribute.from_dtype(
208201
self.buffer,
209202
vertices.dtype,
210-
'texture_coord',
211-
location = self.shader.attributes[ 'in_uv' ]
203+
'texture_coord'
212204
)
213205

214206
def draw( self ):
215207
global vertices
216208

217209
if self.use_shaders:
218210
self.shader.bind()
211+
self.shader.uniforms[ 'in_diffuse_texture' ].value = 0
219212

220213
self.buffer_attributes.push_attributes()
221214

0 commit comments

Comments
 (0)