PDA

View Full Version : IBO's and glDrawElements



Aumnayan
04-09-2014, 11:33 AM
So what I am attempting to do is create multiple pieces of geometry and concate them together into an IBO I can then iterate over displaying each piece of geometry via glDrawElements. I know that I have created & uploaded the VBO correctly, and have the desired index list made. I can see this by replacing the glDrawElements by a glDrawArrays and I get the appropriate geometry on the screen. Which indicates to me that the problem is either how I am uploading the IBO to gl or in the glDrawElements command. I've been over this multiple times and can't seam to pinpoint the problem, is there something obvious going on that I am simply not seeing? Code snippet below:


void SVIS_displayVectorData(SVIS_VECTORDATA *data)
{
int i;

// First we validate the data, then ensure that it's uploaded, then, finaly,
// display it.
if (data && data->vectorLoadComplete) {
if (!data->vboCreateComplete) {
glGenBuffers(1, &data->vbo);
glGenBuffers(1, &data->ibo);
glBindBuffer(GL_ARRAY_BUFFER, data->vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(SVN_VEC3) * data->maxVerticies,
data->verts, GL_DYNAMIC_DRAW);
data->vboCreateComplete = TRUE;
} else {
if (data->zoomLvl != G_mapZoom) {
//NOTE: data->indicies are propogated at this point, TODO: Repopulate based on zoom level.
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, data->ibo);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned int) * data->maxVerticies, // 1:1 ratio of verts to indicies is max case.
data->indicies, GL_DYNAMIC_DRAW);
data->zoomLvl = G_mapZoom;
}

// At this point, we do the actual drawing.
glEnableClientState(GL_VERTEX_ARRAY); // Enable vertex points
glEnable(GL_POLYGON_SMOOTH); // Don't know if this is neccisary
glDepthFunc(GL_ALWAYS); // Don't let terrain be drawn on top

// NOTE: Don't set color or line width here. These should be done by
// the calling procedure.
glBindBuffer(GL_ARRAY_BUFFER, data->vbo);
glVertexPointer(3, GL_FLOAT, sizeof(SVN_VEC3), 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, data->ibo);
for (i = 0; i < data->numElements; i++) {
SVIS_VECTOR_ELEMENT *ptr = &data->elements[i];
glDrawElements(GL_LINE_STRIP, ptr->indicyCount, GL_UNSIGNED_INT,
ptr->startIndicyIndex * sizeof(unsigned int));
//glDrawArrays(GL_LINE_STRIP, ptr->startIndicyIndex, ptr->indicyCount); // NOTE: replacing glDrawElements with this works.
}

glDepthFunc(GL_LESS); // Reset to default
glDisable(GL_POLYGON_SMOOTH); // See comment for Enable
glDisableClientState(GL_VERTEX_ARRAY); // Clean up the gl state.
}
}
}

Aumnayan
04-09-2014, 01:25 PM
Nevermind, I found the problem. The initial state of the system had data->zoomLvl == G_mapZoom causing the IBO not to be allocated/filled.