Thread: [PyOpenGL-Users] VBO question
Brought to you by:
mcfletch
From: Jason H. <Jas...@vo...> - 2011-06-20 19:32:52
|
Hello, I am trying to get VBO's to work using OpenGL.GL.ARB.vertex_buffer_object and am running into issues getting this to work. It basically renders nothing, and I have no clue why it wouldn't. Here is the spirit of what I'm doing. # in my mesh class def build(self): #iterate over faces and build up an array of vertices with interleaved color info vertices.append( [ x, y, z, r, g, b, a ] ) # convert vertices to numpy array # send vertices over to the GPU self.vbo_name = glGenBuffersARB( 1 ) glBindBufferARB( GL_ARRAY_BUFFER_ARB, self.vbo_name ) glBufferDataARB( GL_ARRAY_BUFFER_ARB, vertices, GL_STATIC_DRAW_ARB ) # in my main render loop glEnableClientState( GL_VERTEX_ARRAY ) glEnableClientState( GL_COLOR_ARRAY ) glBindBufferARB( GL_ARRAY_BUFFER_ARB, mesh.vbo_name ) glVertexPointer( 3, GL_FLOAT, 28, 0 ) glColorPointer( 4, GL_FLOAT, 28, 16 ) glDrawArrays( GL_TRIANGLES, 0, mesh.num_raw_vertices ) glDisableClientState( GL_VERTEX_ARRAY ) glDisableClientState( GL_COLOR_ARRAY ) Any help as to what I could possibly be doing wrong here would be really appreciated. Thanks! -Jason ________________________________ 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. |
From: Henry G. <he...@ca...> - 2011-06-20 20:02:56
|
On Mon, 2011-06-20 at 12:20 -0700, Jason Hayes wrote: > # send vertices over to the GPU self.vbo_name = glGenBuffersARB( 1 ) > glBindBufferARB( GL_ARRAY_BUFFER_ARB, self.vbo_name ) > glBufferDataARB( GL_ARRAY_BUFFER_ARB, vertices, GL_STATIC_DRAW_ARB ) I'm not an expert, but don't you still need to copy the data to the buffer. I'm not quite sure how you've managed with 3 arguments there though. The docs all suggest you need 4. After that I think you need to do something like (modified from my pbo code, which is all in terms of numpy arrays, which are well laid out in memory): # Map the buffer object to a pointer vbo_pointer = ctypes.cast(\ GL.glMapBuffer(GL.GL_ARRAY_BUFFER, GL.GL_WRITE_ONLY), ctypes.POINTER(ctypes.c_ubyte)) # Turn that pointer into a numpy array that spans # the whole block.(buffer size is the size of your buffer) vbo_array = numpy.ctypeslib.as_array(vbo_pointer, (buffer_size,)) vbo_array[0:data_size_to_copy] = \ data.view(dtype='uint8').ravel() # Unmap the buffer. GL.glUnmapBuffer(GL.GL_ARRAY_BUFFER) Hope that helps. cheers, Henry |
From: Jason H. <Jas...@vo...> - 2011-06-21 01:29:34
|
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. -Jason ________________________________________ From: Henry Gomersall [he...@ca...] Sent: Monday, June 20, 2011 3:02 PM To: pyo...@li... Subject: Re: [PyOpenGL-Users] VBO question On Mon, 2011-06-20 at 12:20 -0700, Jason Hayes wrote: > # send vertices over to the GPU self.vbo_name = glGenBuffersARB( 1 ) > glBindBufferARB( GL_ARRAY_BUFFER_ARB, self.vbo_name ) > glBufferDataARB( GL_ARRAY_BUFFER_ARB, vertices, GL_STATIC_DRAW_ARB ) I'm not an expert, but don't you still need to copy the data to the buffer. I'm not quite sure how you've managed with 3 arguments there though. The docs all suggest you need 4. After that I think you need to do something like (modified from my pbo code, which is all in terms of numpy arrays, which are well laid out in memory): # Map the buffer object to a pointer vbo_pointer = ctypes.cast(\ GL.glMapBuffer(GL.GL_ARRAY_BUFFER, GL.GL_WRITE_ONLY), ctypes.POINTER(ctypes.c_ubyte)) # Turn that pointer into a numpy array that spans # the whole block.(buffer size is the size of your buffer) vbo_array = numpy.ctypeslib.as_array(vbo_pointer, (buffer_size,)) vbo_array[0:data_size_to_copy] = \ data.view(dtype='uint8').ravel() # Unmap the buffer. GL.glUnmapBuffer(GL.GL_ARRAY_BUFFER) Hope that helps. cheers, Henry ------------------------------------------------------------------------------ EditLive Enterprise is the world's most technically advanced content authoring tool. Experience the power of Track Changes, Inline Image Editing and ensure content is compliant with Accessibility Checking. http://p.sf.net/sfu/ephox-dev2dev _______________________________________________ PyOpenGL Homepage http://pyopengl.sourceforge.net _______________________________________________ PyOpenGL-Users mailing list PyO...@li... https://lists.sourceforge.net/lists/listinfo/pyopengl-users 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. |
From: Henry G. <he...@ca...> - 2011-06-21 08:20:03
|
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 |
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. |