Skip to main content
GameDev.net gamedev.net
🔒 Locked

glDrawRangeElements - unhandled exception

Started by Mantear Mar 27, 2009 at 10:42 AM 1 replies 1.3k views
Original Post
Mantear
Mantear
Greetings! I always have trouble when I try to go back and figure out how VBOs work. I did get them to work for a bit, but in a very non-efficient manner (basically binding/updating data on a per-quad basis in order to transition over from using immediate mode). I was trying to streamline the process, but now I can't even a basic example to work without throwing an unhandled exception. Here's the source code in all its inefficient glory.
int vertex[2][4] = {vertex_x1, vertex_y1, 
                    vertex_x1, vertex_y2, 
                    vertex_x2, vertex_y2, 
                    vertex_x2, vertex_y1};
unsigned char color[4][4] = {255, 255, 255, 255, 
                             255, 255, 255, 255, 
                             255, 255, 255, 255, 
                             255, 255, 255, 255};
float texture[2][4] = {texture_x1, texture_y2, 
                       texture_x1, texture_y1, 
                       texture_x2, texture_y1, 
                       texture_x2, texture_y2};
unsigned int index[4] = {0, 1, 2, 3};

// Vertex
glBindBufferARB(GL_ARRAY_BUFFER, m_VertexVBOId);
glBufferDataARB(GL_ARRAY_BUFFER, sizeof(vertex), &vertex[0], GL_DYNAMIC_DRAW);
// Color
glBindBufferARB(GL_ARRAY_BUFFER, m_ColorVBOId);
glBufferDataARB(GL_ARRAY_BUFFER, sizeof(color), &color[0], GL_DYNAMIC_DRAW);
// Normal
glBindBufferARB(GL_ARRAY_BUFFER, 0);
// Texture
glBindBufferARB(GL_ARRAY_BUFFER, m_TextureVBOId);
glBufferDataARB(GL_ARRAY_BUFFER, sizeof(texture), &texture[0], GL_DYNAMIC_DRAW);

// Index
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, m_IndexVBOId);
glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER, sizeof(index), &index[0], GL_DYNAMIC_DRAW);


// Bind the vertex data.
glBindBufferARB(GL_ARRAY_BUFFER, m_VertexVBOId);
glVertexPointer(2, GL_INT, 0, 0);

// Bind the color data.
glBindBufferARB(GL_ARRAY_BUFFER, m_ColorVBOId);
glColorPointer(4, GL_UNSIGNED_BYTE, 0, 0);

// Bind the texture data.
glBindBufferARB(GL_ARRAY_BUFFER, m_TextureVBOId);
glTexCoordPointer(2, GL_FLOAT, 0, 0);


glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, m_IndexVBOId);
glDrawRangeElements(GL_QUADS, 
                    0, 
                    3, 
                    4, 
                    GL_UNSIGNED_INT, 
                    NULL);
The 'VBOId's are all valid (1, 2, 3, and 4) after calling glGenBuffersARB(). The client states are all enabled. Is it possible that, through previous erroneous runs of the code, I've put the video driver in a bad state and simply need to reboot? Or am I doing something wrong in my code? Thanks.
Mantear
Mantear
Hmm, it seems that my problem was due to having the GL_NORMAL_ARRAY client state enable without giving any data for it, ie, I never call glBindBuffer() followed by glNormalPointer().

Can anyone give a quick run-down on the rules of the client states? When they need to be enabled/disabled and their consequences?
Brother Bob
Brother Bob
There's not much to it really. Enable the arrays you use, and don't enable the others. When done, disable them so you don't get surprises like this when arrays are enabled when you don't expexct them to be.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.