Long story short, I'm trying to do a modal handler that draws using OpenGL into the viewport. Immediate mode through BGL works fine, but is dog slow. I tried using VBOs through BGL but there seems to be no rain dance that makes glVertexAttribPointer work properly.

I've switched to PyOpenGL for the moment and the VBO seems to be created properly. However, drawing corrupts the viewport permanently.

enter image description here

Here's how I'm making the VBO:

class shapes(object):
    triangle = numpy.array(
     [0.0,  2.0, 0.0,
    -2.0, -2.0, 0.0,
     2.0, -2.0, 0.0],

vbo = glGenBuffers( 1 )
error = glGetError()
if error:
    raise Exception("glGenBuffers: Error {}".format(error))

glBindBuffer( GL_ARRAY_BUFFER, vbo )
error = glGetError()
if error:
    raise Exception("glBindBuffer: Error {}".format(error))

glBufferData( GL_ARRAY_BUFFER, shapes.triangle.tostring(), GL_STATIC_DRAW )
error = glGetError()
if error:
    raise Exception("glBufferData: Error {}".format(error))

glVertexAttribPointer( 0, 3, GL_FLOAT, GL_FALSE, 0, c_void_p(0) )
error = glGetError()

if not error == 0:
    if error == GL_INVALID_VALUE:
        raise Exception("Too many attribs.")

    if error == GL_INVALID_ENUM:
        raise Exception("Wrong Type.")

    if error == GL_INVALID_OPERATION:
        raise Exception("Dunno.")

print( "Attrib pointer fine." )

glEnableVertexAttribArray( 0 )
error = glGetError()
if error:
    raise Exception("glBufferData: Error {}".format(error))

gc_guard['vbo'] = vbo
glBindBuffer( GL_ARRAY_BUFFER, 0 )

And here's the draw:

glBindBuffer( GL_ARRAY_BUFFER, gc_guard['vbo'] )
glDrawArrays(GL_TRIANGLES, 0, 3)
glBindBuffer( GL_ARRAY_BUFFER, 0 )

I'm obviously doing something wrong, but as an OpenGL newbie I'm not sure what it is.

Is there a prescribed way to draw using VBOs here that I've missed? Or is it possible that the Python VBO indexes and the ones tracked by C++ are out of sync, and I'm overwriting a VBO that Blender has already created?

Thanks in advance.



You must log in to answer this question.

Browse other questions tagged .