In the last few days, I created the windowing, contexting and eventhandling API with Cython on top of GLFW. It is super fast and working really nicely -- most of the time:)
Today I started testing some more advanced drawing techniques than the immidiate drawing mode (glBegin/glEnd) I used to testing if the context is working.
Even though the Vertex Arrays are working the Vertex Buffer objects are not, and I can not figure out why -- where is the problem? Do I have to enable something else? The problem is in the Cython code (syntax, pointers, etc..)?
This is my main python code, which imports the GLFW-based window I created, and adds a rendering event to it, which is the on_draw() method, which is called at the end of the event loop:
import lib.pycasso.window
import lib.pycasso.graphics
class Window(lib.pycasso.window.Window):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
def on_draw(self):
lib.pycasso.graphics.draw()
Window().run()
It also imports the graphics module, which contains the actual OpenGL drawing calls, it looks like this:
from GL.gl cimport *
from GL.glu cimport *
# Vertex buffer object identifier
cdef unsigned int vbo
# An interleaved array
cdef float* array = [ -2, -2, 0, # Vertex
1, 0, 0, # Color
2, 0, 0,
0, 1, 0,
0, 2, 0,
0, 0, 1 ]
glGenBuffers( 1, &vbo )
glBindBuffer( GL_ARRAY_BUFFER, vbo )
glBufferData( GL_ARRAY_BUFFER, sizeof( array ), array, GL_STATIC_DRAW )
cpdef draw():
glClear( GL_COLOR_BUFFER_BIT )
glLoadIdentity()
gluLookAt( 0, 0, 10,
0, 0, 0,
0, 1, 0 )
glBindBuffer( GL_ARRAY_BUFFER, vbo )
glEnableClientState( GL_VERTEX_ARRAY )
glEnableClientState( GL_COLOR_ARRAY )
glVertexPointer( 3, GL_FLOAT, 6*sizeof( float ), NULL )
glColorPointer( 3, GL_FLOAT, 6*sizeof( float ), <void*>(3*sizeof( float )))
glDrawArrays( GL_TRIANGLES, 0, 3 )
glDisableClientState( GL_COLOR_ARRAY )
glDisableClientState( GL_VERTEX_ARRAY )
glBindBuffer( GL_ARRAY_BUFFER, 0 )
Now any time I run the main python file, the window appears, then colors to black (which means, it is clearing the color buffer (first line in on_draw method)) and then it quits, and gives me the:
Finished in 1.0s with exit code -11
Any idea on what am I doing wrong?
Thank you very much,
P