Re: [PyOpenGL-Users] VBO question
Brought to you by:
mcfletch
From: Jason H. <Jas...@vo...> - 2011-06-21 14:29:15
|
Sure thing. Here is basically everything I changed to get this to work. I'm not an expert in OGL, so I could be doing some things wrong. from ctypes import c_void_p from OpenGL.GL import * from OpenGL.GL.ARB.vertex_buffer_object import * import OpenGL.arrays.arraydatatype import numpy ## Right after OGL is initialized ## if glInitVertexBufferObjectARB(): # build meshes # compile shaders ## When a mesh is being built ## ADT = OpenGL.arrays.arraydatatype.ArrayDatatype # iterate over each face and build up vertices vertices.append( [ x, y, z, r, g, b, a ] ) # convert vertices to a numpy array # send vertices to the GPU vb_name = glGenBuffersARB( 1 ) glBindBufferARB( GL_ARRAY_BUFFER_ARB, vb_name ) glBufferDataARB( GL_ARRAY_BUFFER_ARB, ADT.arrayByteCount( vertices ), ADT.voidDataPointer( vertices ), GL_STATIC_DRAW_ARB ) ## In the mesh bind function ## glBindBufferARB( GL_ARRAY_BUFFER_ARB, vb_name ) # bind vertex id = getGetAttribLocation( shader, "position" ) glEnableVertexAttribArray( id ) glVertexAttribPointer( id, 3, GL_FLOAT, GL_FALSE, sizeof( vertex ), None ) # bind color id = getGetAttribLocation( shader, "color" ) glEnableVertexAttribArray( id ) glVertexAttribPointer( id, 4, GL_FLOAT, GL_FALSE, sizeof( vertex ), c_void_p( OFFSET_VERTEX_COLOR ) ) ## In my main render loop ## glUseProgramObjectARB( shader ) mesh.bind( ) glDrawArrays( GL_TRIANGLES, 0, mesh.num_raw_verts ) mesh.unbind( ) glUseProgramObjectARB( shader ) -Jason -----Original Message----- From: W.H. Gomersall [mailto:wh...@he...] On Behalf Of Henry Gomersall Sent: Tuesday, June 21, 2011 3:20 AM To: Jason Hayes Cc: pyo...@li... Subject: RE: [PyOpenGL-Users] VBO question On Mon, 2011-06-20 at 18:29 -0700, Jason Hayes wrote: > Thanks for the reply Henry. After a lot of trial and error, I finally > figured out what the real problem is. I'm on OpenGL 3.3 and > glVertexPointer and the others have been deprecated since 3.0, but > PyOpenGL tries to maintain backwards compatability I guess. So I > figured out the correct method and switched to glVertexAttribPointer > and wrote a GLSL shader, now everything works great. For my benefit as much as others, would you share the code snippet that loads the vertex array? Thanks, Henry This message, including any attachments, may contain privileged and/or confidential information. Any distribution or use of this email by anyone other than the intended recipient(s) is strictly prohibited. If you are not the intended recipient, please notify the sender immediately and delete all copies. Thank you. |