Re: [PyOpenGL-Users] VBO help and performance
Brought to you by:
mcfletch
From: Wakefield, R. <rjw...@en...> - 2010-05-02 07:31:25
|
I finally managed to get things working with the VBOs (big thanks to Ian Mallett for the tip on the VBO class), but I have one question left. I noticed in the pyOpenGL spec that glVertexPointer (and the others) are deprecated and scheduled to be removed in the newer OpenGL versions. Is the only replacement using a GLSL shader? If not, what's the other option. I found a helpful example in the mail archive here: http://blog.gmane.org/gmane.comp.python.opengl.user/month=20090801 using that (also see vboattrib.py by clicking on '17 comments' for Josh Davis; you'll have to rename the bin file to .py), but I'm not really sure how to apply this to simple tiling. What is the quickest way to set vloc/tloc so OpenGL know that these are the vertices/textures respectively so the code below works? # main body of drawVBO in the draw loop vbo.bind() glVertexAttribPointer(vloc, 2, GL_FLOAT, False, 0, vbo) # vertex location, start of VBO glVertexAttribPointer(tloc, 2, GL_FLOAT, False, 0, vbo + (len(vbo)/2*4)) #texture location, halfway through VBO glEnableVertexAttribArray(vloc) glEnableVertexAttribArray(tloc) glDrawArrays(GL_TRIANGLES, 0, len(vbo)/2) glDisableVertexAttribArray(vloc) glDisableVertexAttribArray(tloc) vbo.unbind() For reference, the working code I use with vertex pointers is below. My earlier problem was apparently doing the glBufferData call wrong, and in case this helps anyone else the VBO class is a helpful way to outsource the job. By the way, does interleaving data offer a good performance gain over a linear VBO (list of verts, then colors, then textures)? # in the initialization; vbo3 is passed to drawVBO later. dat = verts[:] + textures[:] # a flat list works fine vbo3 = VBO(numpy.asarray(dat, 'f'), GL_STATIC_DRAW, GL_ARRAY_BUFFER) def drawVBO(texid, vbo): glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glBindTexture( GL_TEXTURE_2D, texid) vbo.bind() glEnableClientState(GL_VERTEX_ARRAY) glEnableClientState(GL_TEXTURE_COORD_ARRAY) glVertexPointer(2, GL_FLOAT, 0, vbo) glTexCoordPointer(2, GL_FLOAT, 0, vbo + (len(vbo)/2*4)) # the *4 accounts for sizeof(float) glDrawArrays(GL_TRIANGLES, 0, len(vbo)/2) glDisableClientState(GL_TEXTURE_COORD_ARRAY) glDisableClientState(GL_VERTEX_ARRAY) vbo.unbind() glFlush() glFinish() ''' I'm using pygame, so I pygame put it all on the screen; GLUT can do the same ''' pygame.display.flip() |