I'm trying to pack my homemade vertex struct into a VBO and send it off to be rendered.
Currently, it looks like I got the geometry right. The trouble concerns the
colours, that are a part of my struct:
struct opaque_vertex{ float x, y, z; // Vertex (3*4 bytes) float r, g, b; // Color (3*4 bytes) float padding[2]; // Padding to reach 32 bytes (2*4 bytes)};
The colours are set properly after the vertex coords have been set.
They are basically just the x,y,z -components scaled according to some
maximum on each axis.
I recently changed to this from using two seperate vectors of vertices,
one for position and one for color.
I thoght I liked this the most. Keeps things simple, and should be quite fast.
Now, when I have created my VBO, I use this for rendering:
glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo_id);glVertexPointer(3, GL_FLOAT, sizeof(float)*8, NULL);glColorPointer(3, GL_FLOAT, sizeof(float)*8, NULL);glEnableClientState(GL_VERTEX_ARRAY);glEnableClientState(GL_COLOR_ARRAY);glDrawArrays(GL_QUADS, 0, vertex_count);glDisableClientState(GL_COLOR_ARRAY);glDisableClientState(GL_VERTEX_ARRAY);
Only I'm a little worried about all those arrays there, I should have just one,
and a single vertex buffer with all the required information.
I'm also passing NULL as the offset for color data, but if I want to forget my
static vertex data, my vertex list is gone at this point my VBO has been created,
so it's not like I can retrieve a proper address for the colour part.
EDIT (But what does it look like?):
But the colours shown clearly represents the positions of the vertices.
Ex, a vertex ocurring in 0,0,0 (before translations, naturally) will be black,
and vertices from >1,0,0 will be red. Most of the vertices thus, are white.
What am I doing wrong?
[Edited by - SuperVGA on August 23, 2010 7:24:00 AM]