Page 1 of 1

OpenGL renderer : conflict with glBindBuffer() & glBufferDat

Posted: Fri Apr 01, 2005 23:02
by shat
Hello!

I have some (maybe serious, maybe not) problem. My program uses vertex and index buffers to draw a terrain. When I add the following lines to a program using CEGUI with OpenGL Renderer, the program flies away with a nice Access Violation exception.

Code: Select all

   int vertex_buffer_size = 128*128; // Size is irrelevant
   int index_buffer_size = 128*128;

   glGenBuffers(2, vertex_buffer);
   glGenBuffers(2, index_buffer);

   glBindBuffer(GL_ARRAY_BUFFER_ARB, vertex_buffer[0]);
   glBufferData(GL_ARRAY_BUFFER_ARB, vertex_buffer_size, 0, GL_STREAM_DRAW_ARB);
   glBindBuffer(GL_ARRAY_BUFFER_ARB, vertex_buffer[1]);
   glBufferData(GL_ARRAY_BUFFER_ARB, vertex_buffer_size, 0, GL_STREAM_DRAW_ARB);

   glBindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB, index_buffer[0]);
   glBufferData(GL_ELEMENT_ARRAY_BUFFER_ARB, index_buffer_size, 0, GL_STREAM_DRAW_ARB);
   glBindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB, index_buffer[1]);
   glBufferData(GL_ELEMENT_ARRAY_BUFFER_ARB, index_buffer_size, 0, GL_STREAM_DRAW_ARB);


The error occurs at the first execution of the OpenGLRenderer::renderVBuffer(), in the line

Code: Select all

      glDrawArrays(GL_TRIANGLES, 0, d_bufferPos);


I don't know what to do, because I don't understand the problem. What does the element array buffer do with the drawing of a totally different triangle array?

I'm using a GeForce 4 Ti4200, with the 61.77 ForceWare nVidia driver.

Thanks for the help!
shat

Re: OpenGL renderer : conflict with glBindBuffer() & glBuffe

Posted: Sat Apr 02, 2005 11:17
by rincewind
Hi,

you never "unbind" the buffers you use, so CEGUI's draw call tries to use the pointer supplied as an offset into your buffers (VBOs).

After you are done drawing with your buffers, reset GL to "normal" vertex/index array mode by doing:

Code: Select all

glBindBuffer(GL_ARRAY_BUFFER_ARB, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB, 0);


Hope this helps,

Rincewind