[PyOpenGL-Users] Using Vertex and index buffer objects in glDrawElements(...)
Brought to you by:
mcfletch
From: Richard G. <rgu...@gm...> - 2009-11-06 17:01:11
|
Hi, I’d like to know what I am doing wrong. I want to transfer an array with vertices and another one with index data into buffers on the graphics card and use them in a drawElements(..) call. As a beginner with OpenGL (coming from Java3d), I am looking for an example that works with PyOpenGL. The C code that I have found on the Internet does not really help in this context because the problem is possibly my lack of understanding the PyOpenGL wrapping. Here is the code I tried: class Widget3D: … def On_init( … ): … # initialize data: just a small coordinates frame for use with GL_LINES verts=array([[ 0,0,0 ], [ 9,0,0 ], [ 0,9,0 ], [ 0,0,9 ]], dtype=float32) idxs = array([ 0,1, 0,2, 0,3],dtype=ubyte) # initialize buffers bf=glGenBuffers(1) glEnableClientState(GL_VERTEX_ARRAY) usage = GL_DYNAMIC_DRAW glBindBuffer(GL_ARRAY_BUFFER, bf) glBufferData(GL_ARRAY_BUFFER, verts, usage) glBindBuffer(GL_ARRAY_BUFFER, 0) # I know I should store the size and type of the data as well; for the test I just insert the values in the rendering call because I know them self.bf=bf ibf = glGenBuffers(1) usage = GL_DYNAMIC_DRAW glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibf) glBufferData(GL_ELEMENT_ARRAY_BUFFER, idxs, usage) glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0) self.ibf=ibf # Method called for each redraw def drawGL(…): glBindBuffer(GL_ARRAY_BUFFER, self.bf) glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, self.ibf) glEnableClientState(GL_VERTEX_ARRAY) # This line is needed to make drawArrays(…) work but may be harmful in context of Index buffer glVertexPointer(3,GL_FLOAT,0,None) # perhaps the last argument should not be 0; I tried None but does not work either # possibly I should use something connected with c_void_ptr but I dont know the syntax glDrawElements(GL_LINES,6, GL_UNSIGNED_BYTE,0) # the following line works fine (if I do not bind the index buffer) which makes me suspect it has something to do with the index buffer # a reading mapBuffer(…) call gives the right content for the index buffer, so the data transfer to the card worked # glDrawElementsui(GL_LINES, [0,1,0,2,0,3]) I am using the OpenGL code in a PyQt QGLWidget subclass; perhaps the issue comes from there. Usually, the application just crashes if I try to execute the code. Please help me to find the right way of convincing PyOpenGL to draw my arrays. Thanks Richard -- DSL-Preisknaller: DSL Komplettpakete von GMX schon für 16,99 Euro mtl.!* Hier klicken: http://portal.gmx.net/de/go/dsl02 |