I'm creating two different vertex buffers, that use two different shaders to render them. As soon as I bind the second vertex buffer, the data I parked in the first vertex buffer seems to be corrupted or lost.
If I generate and draw one vertex buffer only, like so:
glGenBuffers( 1, &vb1 ) ;
glBindBuffer( GL_ARRAY_BUFFER, vb1 ) ;
// fill it..
glBufferData( .. )
Then, in the draw() loop,
glUseProgram( shader1 ) ;
glBindBuffer( vb1 ) ; // make sure it is bound
glDrawArrays( ... ) // draw it
Then it works fine, no problems, no errors (I am glGettingLastError() after every gl* call, so it seems this code is perfectly fine)
Now if I so much as generate and bind a second vertex buffer, any time after the first one was generated and bound,
// ran in init() -- then previously working code in draw() is broken
glGenBuffers( 1, &vb2 ) ; // ok.. no problems with this line
glBindBuffer( GL_ARRAY_BUFFER, vb2 ) ; // spoils data in vb1?
As soon as I call glBindBuffer
with this newly generated vb2
buffer, it seems the data in vb1
is completely dumped or lost. On attempts to draw vb1
(not vb2
!), i get this crash:
I even filled the array with GL_STATIC_DRAW
.
I don't understand, I thought these vertex buffers were supposed to retain data, even if another vertex buffer is created and initialized? .. what am I doing wrong?