Re: [PyOpenGL-Users] Help with VAOs
Brought to you by:
mcfletch
From: rndblnch <rnd...@gm...> - 2015-02-23 15:42:21
|
Johannes Bauer <dfnsonfsduifb <at> gmx.de> writes: > > Hello list, > > I'm trying to store objects (currently only vertices) on the graphics > card so that I can avoid lots of: > > glBegin() > glVertex(...) > [...] > glEnd() you may find this tutorial useful: https://bitbucket.org/rndblnch/opengl-programmable/src it shows the transformation of a minimal sample from direct mode to the "modern" programmable pipeline step by step. you can easily diff two successive versions of the code, e.g.: diff 01-direct.py 03-array.py 5c5 < 01-direct.py --- > 03-array.py 7c7 < OpenGL 1.0 rendering using per vertex primitive --- > OpenGL 1.1 rendering using arrays 71a72,75 > def flatten(*lll): > return [u for ll in lll for l in ll for u in l] > > 72a77,83 > # enabling arrays > glEnableClientState(GL_VERTEX_ARRAY) > glEnableClientState(GL_TEXTURE_COORD_ARRAY) > glEnableClientState(GL_NORMAL_ARRAY) > glEnableClientState(GL_COLOR_ARRAY) > > # model data 76,79c87,90 < verticies, tex_coords, normals, colors = (model.verticies, < model.tex_coords, < model.normals, < model.colors) --- > verticies = flatten(model.verticies) > tex_coords = flatten(model.tex_coords) > normals = flatten(model.normals) > colors = flatten(model.colors) 82a94,98 > glVertexPointer(3, GL_FLOAT, 0, verticies) > glTexCoordPointer(3, GL_FLOAT, 0, tex_coords) > glNormalPointer(GL_FLOAT, 0, normals) > glColorPointer(3, GL_FLOAT, 0, colors) > 90,97c106,108 < glBegin(GL_TRIANGLE_STRIP) < for i in range(offset, offset+size): < index = indicies[i] < glColor3f(*colors[index]) < glNormal3f(*normals[index]) < glTexCoord3f(*tex_coords[index]) < glVertex3f(*verticies[index]) < glEnd() --- > glDrawElements(GL_TRIANGLE_STRIP, > size, GL_UNSIGNED_INT, > indicies[offset:offset+size]) renaud |