PDA

View Full Version : indexed drawing



sandbucket
06-04-2013, 08:18 AM
hi all. im reading the new opengl programming guide and there is something that is uffer bound the bunclear to me about indexing. on page 122 the list of vertices and colors bound to GL_ARRAY_BUFFER are not seperated into seperate vertices by a set of curly braces, ie:
the way it is in the book:
float vertices[]{
0.5, 0, 1.5, 1,
0.5, 1, 1.2, 1,
-0.5, 1, 1.3, 1
};

the way i thought it was until i found the example:
float vertices[][]{
{0.5, 0, 1.5, 1},
{0.5, 1, 1.2, 1},
{-0.5, 1, 1.3, 1}
};

so how does it read the vertexes when they aren't seperated and do you have to specify the size (number of elements in vertex) of the vertex to the program at some point and if so how do you do that?
thanks alot

mhagain
06-04-2013, 09:35 AM
This is specified by your glVertexAttribPointer (http://www.opengl.org/sdk/docs/man/xhtml/glVertexAttribPointer.xml) call; the relevant parameters are:

size: in this case it looks like 4 components (x, y, z and w) per vertex.
type: GL_FLOAT here.
stride: the number of bytes from the start of one vertex to the start of the next, or 0 if the data is tightly packed. Here you could give either 0 or (4 * sizeof (float)).

You're better off reading on in the book, as all of this will be covered - it's pretty fundamental knowledge.

sandbucket
06-04-2013, 02:11 PM
kk, i understand now. thanks lots