I have problems understanding how to use one buffer with 3 different data in it, I have the following structure for my vert,text,color data:
struct xyzf {
float x, y, z;
};
struct xyf {
float x, y;
};
struct vertype {
xyzf points[4];
};
struct textype {
xyf points[4];
};
struct coltype {
GLuint points[4];
};
struct buftype {
vertype vertex;
textype texcoord;
coltype color;
};
Then I (try to) use it in the following way (which makes most sense to me):
glBindBufferARB(GL_ARRAY_BUFFER, mybufid);
glVertexPointer(3, GL_FLOAT, sizeof(buftype), 0);
glTexCoordPointer(2, GL_FLOAT, sizeof(buftype), (GLvoid *)sizeof(vertype));
glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(buftype), (GLvoid *)(sizeof(vertype)+sizeof(textype)));
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glDrawArrays(GL_QUADS, 0, indices);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
glBindBufferARB(GL_ARRAY_BUFFER, 0); // unbind
But it fails, and its rendering something else than what I got with setting stride and pointers to zero all. When I do that, I get my vertex data correctly rendered, but text/color still incorrect.
I can’t use &data[0].vertex for the last param in glVertexPointer() etc. because I don’t have the data anymore since I am using a VBO, that method works only with vertex arrays.
Also I’m not sure how the count value for glDrawArrays() works, I read docs which say it is the indices, so a quad would have 4, right? But when I multiply the count of quads by 4, it only renders HALF of my vertices, whats going on there? (it will render them all if I multiply by 8…)
It seems you are interleaving your data per quad, but you should rather interleave it per vertex (at least that’s what usually done).
Your code should be right if you change the vertex layout to this:
Rather than