Skip to content

Commit c99b642

Browse files
Fix VBO usage in legacy renderables.
Code was updated but not tested. Now tested and working in both GL Core and Legacy.
1 parent 437fda6 commit c99b642

File tree

4 files changed

+36
-28
lines changed

4 files changed

+36
-28
lines changed

pygly/examples/renderable_colour_cube.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from OpenGL import GL
55

66
from pygly.shader import Shader, VertexShader, FragmentShader, ShaderProgram
7-
from pygly.vertex_buffer import VertexBuffer, BufferAttributes, GenericAttribute, VertexAttribute, TextureCoordAttribute
7+
from pygly.vertex_buffer import VertexBuffer, BufferAttributes, GenericAttribute, VertexAttribute
88
from pygly.vertex_array import VertexArray
99

1010

@@ -200,7 +200,7 @@ def __init__( self ):
200200
)
201201

202202
self.buffer_attributes = BufferAttributes()
203-
self.buffer_attributes[ 'position' ] = GenericAttribute.from_dtype(
203+
self.buffer_attributes[ 'position' ] = VertexAttribute.from_dtype(
204204
self.buffer,
205205
vertices.dtype,
206206
'position',
@@ -211,19 +211,19 @@ def draw( self, colour ):
211211
if self.use_shaders:
212212
self.shader.bind()
213213

214-
self.buffer.bind()
215-
self.buffer.push_attributes()
214+
self.buffer_attributes.push_attributes()
216215

217216
# set the gl colour
218217
GL.glColor4f( *colour )
219218

220219
# set the vertex pointer to the position data
220+
self.buffer.bind()
221221
self.buffer_attributes.set()
222+
self.buffer.unbind()
222223

223224
GL.glDrawArrays( GL.GL_TRIANGLES, 0, len( vertices ) )
224225

225-
self.buffer.pop_attributes()
226-
self.buffer.unbind()
226+
self.buffer_attributes.pop_attributes()
227227

228228
if self.use_shaders:
229229
self.shader.unbind()

pygly/examples/renderable_cube.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from OpenGL import GL
55

66
from pygly.shader import Shader, VertexShader, FragmentShader, ShaderProgram
7-
from pygly.vertex_buffer import VertexBuffer, BufferAttributes, GenericAttribute, VertexAttribute, TextureCoordAttribute
7+
from pygly.vertex_buffer import VertexBuffer, BufferAttributes, GenericAttribute, VertexAttribute, ColourAttribute
88
from pygly.vertex_array import VertexArray
99

1010

@@ -155,6 +155,8 @@ def __init__( self ):
155155
self.vao.unbind()
156156

157157
def draw( self, projection, model_view ):
158+
global vertices
159+
158160
self.shader.bind()
159161
self.shader.uniforms[ 'projection' ].value = projection
160162
self.shader.uniforms[ 'model_view' ].value = model_view
@@ -211,35 +213,37 @@ def __init__( self ):
211213
data = vertices,
212214
)
213215

214-
self.position = GenericAttribute.from_dtype(
216+
self.buffer_attributes = BufferAttributes()
217+
self.buffer_attributes[ 'position' ] = VertexAttribute.from_dtype(
215218
self.buffer,
216219
vertices.dtype,
217220
'position',
218221
location = self.shader.attributes[ 'in_position' ]
219222
)
220223

221-
self.colour = GenericAttribute.from_dtype(
224+
self.buffer_attributes[ 'colour' ] = ColourAttribute.from_dtype(
222225
self.buffer,
223226
vertices.dtype,
224227
'colour',
225228
location = self.shader.attributes[ 'in_colour' ]
226229
)
227230

228231
def draw( self ):
232+
global vertices
233+
229234
if self.use_shaders:
230235
self.shader.bind()
231236

232-
self.buffer.bind()
233-
self.buffer.push_attributes()
237+
self.buffer_attributes.push_attributes()
234238

235239
# set the vertex pointer to the position data
236-
self.position.set()
237-
self.colour.set()
240+
self.buffer.bind()
241+
self.buffer_attributes.set()
242+
self.buffer.unbind()
238243

239244
GL.glDrawArrays( GL.GL_TRIANGLES, 0, len( vertices ) )
240245

241-
self.buffer.pop_attributes()
242-
self.buffer.unbind()
246+
self.buffer_attributes.pop_attributes()
243247

244248
if self.use_shaders:
245249
self.shader.unbind()

pygly/examples/renderable_textured_quad.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,14 +197,14 @@ def __init__( self ):
197197
)
198198

199199
self.buffer_attributes = BufferAttributes()
200-
self.buffer_attributes[ 'position' ] = GenericAttribute.from_dtype(
200+
self.buffer_attributes[ 'position' ] = VertexAttribute.from_dtype(
201201
self.buffer,
202202
vertices.dtype,
203203
'position',
204204
location = self.shader.attributes[ 'in_position' ]
205205
)
206206

207-
self.buffer_attributes[ 'uv' ] = GenericAttribute.from_dtype(
207+
self.buffer_attributes[ 'uv' ] = TextureCoordAttribute.from_dtype(
208208
self.buffer,
209209
vertices.dtype,
210210
'texture_coord',
@@ -217,16 +217,16 @@ def draw( self ):
217217
if self.use_shaders:
218218
self.shader.bind()
219219

220-
self.buffer.bind()
221-
self.buffer.push_attributes()
220+
self.buffer_attributes.push_attributes()
222221

223222
# set the vertex pointer to the position data
223+
self.buffer.bind()
224224
self.buffer_attributes.set()
225+
self.buffer.unbind()
225226

226227
GL.glDrawArrays( GL.GL_TRIANGLES, 0, len( vertices ) )
227228

228-
self.buffer.pop_attributes()
229-
self.buffer.unbind()
229+
self.buffer_attributes.pop_attributes()
230230

231231
if self.use_shaders:
232232
self.shader.unbind()

pygly/examples/renderable_triangle.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from OpenGL import GL
55

66
from pygly.shader import Shader, VertexShader, FragmentShader, ShaderProgram
7-
from pygly.vertex_buffer import VertexBuffer, BufferAttributes, GenericAttribute, VertexAttribute, TextureCoordAttribute
7+
from pygly.vertex_buffer import VertexBuffer, BufferAttributes, GenericAttribute, VertexAttribute, ColourAttribute
88
from pygly.vertex_array import VertexArray
99

1010

@@ -119,6 +119,8 @@ def __init__( self ):
119119
self.vao.unbind()
120120

121121
def draw( self, projection, model_view ):
122+
global vertices
123+
122124
self.shader.bind()
123125
self.shader.uniforms[ 'projection' ].value = projection
124126
self.shader.uniforms[ 'model_view' ].value = model_view
@@ -176,33 +178,35 @@ def __init__( self ):
176178
)
177179

178180
self.buffer_attributes = BufferAttributes()
179-
self.buffer_attributes[ 'position' ] = GenericAttribute.from_dtype(
181+
self.buffer_attributes[ 'position' ] = VertexAttribute.from_dtype(
180182
self.buffer,
181183
vertices.dtype,
182184
'position',
183185
location = self.shader.attributes[ 'in_position' ]
184186
)
185-
self.buffer_attributes[ 'colour' ] = GenericAttribute.from_dtype(
187+
self.buffer_attributes[ 'colour' ] = ColourAttribute.from_dtype(
186188
self.buffer,
187189
vertices.dtype,
188190
'colour',
189191
location = self.shader.attributes[ 'in_colour' ]
190192
)
191193

192194
def draw( self ):
195+
global vertices
196+
193197
if self.use_shaders:
194198
self.shader.bind()
195199

196-
self.buffer.bind()
197-
self.buffer.push_attributes()
200+
self.buffer_attributes.push_attributes()
198201

199202
# set the vertex pointer to the position data
203+
self.buffer.bind()
200204
self.buffer_attributes.set()
205+
self.buffer.unbind()
201206

202207
GL.glDrawArrays( GL.GL_TRIANGLES, 0, len( vertices ) )
203208

204-
self.buffer.pop_attributes()
205-
self.buffer.unbind()
209+
self.buffer_attributes.pop_attributes()
206210

207211
if self.use_shaders:
208212
self.shader.unbind()

0 commit comments

Comments
 (0)