Interleaved VBO troubles

So, here’s my problem. I made a static interleaved VBO for my terrain, which worked just fine, as shown in the picture below.

But, when adding color to it, this happens. (Two images, because two things happen).

As shown in those images, a massive red anomaly shows up, as well as half of one of the walls are gone. I am wondering why this is happening, since I am suspisious that the draw code is the culprit, I’m posting the code in which the anomaly shows up, as well as when it doesn’t.

Draw Code With Anomaly:


int stride = 12 * (Float.SIZE / Byte.SIZE);
glPushMatrix();
    glBindBuffer(GL_ARRAY_BUFFER, vboID);
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glEnableClientState(GL_NORMAL_ARRAY);
    glEnableClientState(GL_COLOR_ARRAY);
        glVertexPointer(3, GL_FLOAT, stride, 0L);
        glNormalPointer(GL_FLOAT, stride, (Float.SIZE / Byte.SIZE) * 3);
        glTexCoordPointer(2, GL_FLOAT, stride, (Float.SIZE / Byte.SIZE) * 6);
        glColorPointer(4, GL_FLOAT, stride, (Float.SIZE / Byte.SIZE) * 9);
	glDrawArrays(GL_TRIANGLES, 0, vertexLen);
    glDisableClientState(GL_COLOR_ARRAY);
    glDisableClientState(GL_NORMAL_ARRAY);
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    glDisableClientState(GL_VERTEX_ARRAY);
    glBindBuffer(GL_ARRAY_BUFFER, 0);
glPopMatrix();

Draw Code without Anomaly:


int stride = 8 * (Float.SIZE / Byte.SIZE);
glPushMatrix();
    glBindBuffer(GL_ARRAY_BUFFER, vboID);
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glEnableClientState(GL_NORMAL_ARRAY);
        glVertexPointer(3, GL_FLOAT, stride, 0L);
        glNormalPointer(GL_FLOAT, stride, (Float.SIZE / Byte.SIZE) * 3);
        glTexCoordPointer(2, GL_FLOAT, stride, (Float.SIZE / Byte.SIZE) * 6);
        glDrawArrays(GL_TRIANGLES, 0, vertexLen);
    glDisableClientState(GL_NORMAL_ARRAY);
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    glDisableClientState(GL_VERTEX_ARRAY);
    glBindBuffer(GL_ARRAY_BUFFER, 0);
glPopMatrix();

Well if it helps, your error is with:

glColorPointer(4, GL_FLOAT, stride, (Float.SIZE / Byte.SIZE) * 9);

Shouldn’t that be a multiple of 4? ie:

glColorPointer(4, GL_FLOAT, stride, (Float.SIZE / Byte.SIZE) * 12);

CopyableCougar4.

No, that shouldn’t be a 4, that’s the offset for the buffer, so when I say (Float.SIZE / Byte.SIZE) * 9, I’m offsetting to the color parts of the buffer, which start at (Float.SIZE / Byte.SIZE) * 9, (Float.SIZE / Byte.SIZE) * 4 is within the texture coordinates, or normals.

Oh, thought you meant multiply it by 4, no, that didn’t work at all, there is nothing at that part of the buffer.

Another chance to post this awesome guide by our overlord! :slight_smile:

Mike

One of these days I’ll add a proper, non-deprecated opengl version.