glDrawArrays

Hello,
I have a simple question regaring glDrawArrays.
According to my redbook glDrawArrays constructs a sequence of geometric primitives of all enabled arrays starting at index first and ending at first+count-1.
But is that true? Because if you have a simple texture for your primtives, it’s likly to have just 2 coordinates per texture-coordinate, while you might have 3 coordinates for normals and vertices.
So my question is, is it possible to have 3 coords for vertices, and 2 for tex coords. And if that’s possible, what value should I pass to the parameter count of the function glDrawArrays?
I hope that my problem is clear enough.
Thanks in advance,
Hylke

Yes it’s possible, the count value should be the number of vertics you have.

OpenGL array draw commands cannot be fed from data pools with different array lengths.

Although you can freely mix arrays of attributes with different number of components, all arrays must provide data per vertex.

Most common example: You can not render a textured lit cube with an array draw command from 8 vertices, 6 normals, and 4 texcoords.
Instead all your arrays need to be 24 attributes long, because the combination of the attributes gives you 24 unique vertices.

Originally posted by Relic:
[b] OpenGL array draw commands cannot be fed from data pools with different array lengths.

Although you can freely mix arrays of attributes with different number of components, all arrays must provide data per vertex.

Most common example: You can not render a textured lit cube with an array draw command from 8 vertices, 6 normals, and 4 texcoords.
Instead all your arrays need to be 24 attributes long, because the combination of the attributes gives you 24 unique vertices. [/b]
So what you’re saying is, I can have 2 texture coordinates per vertex, but the array of texture coordinates should still equal to the length of the vertex array?

All arrays you use can have different formats. For example, vertex array can hold three-component vectors while - as you stated - the texture coordinate array may only hold two-component vectors.
What DrawArrays basically does is following:

 
 for(int i = start; i < start+count-1; i++):
   Normal(normal_array(i));
   TexCoord(texcoords_array(i));
   ...
   Vertex(vertex_array(i));
 

As you can see, this parameters refer to the number of vertices and not to the number of components per array: the elements of the array with teh same index are being combined to a single vertex.

P.S. This is also well-explained in the OpenGL specification. A very good read :slight_smile: You need no books on OpenGL except it.

Originally posted by Zengar:
[b] All arrays you use can have different formats. For example, vertex array can hold three-component vectors while - as you stated - the texture coordinate array may only hold two-component vectors.
What DrawArrays basically does is following:

 
 for(int i = start; i < start+count-1; i++):
   Normal(normal_array(i));
   TexCoord(texcoords_array(i));
   ...
   Vertex(vertex_array(i));
 

As you can see, this parameters refer to the number of vertices and not to the number of components per array: the elements of the array with teh same index are being combined to a single vertex.

P.S. This is also well-explained in the OpenGL specification. A very good read :slight_smile: You need no books on OpenGL except it. [/b]
Ok, thank you for your reply.
I think I’Il have to use 3 coordinates per texture vertex, because I use multiple glDrawArrays, on a single buffer, and you can’t set pos for a specific buffer(Because the vertexpos and texcoordpos differs, because of their difference in coordinates per call).

I am not shure I understand what you say oO

OpenGL doesn’t bother how many coordinates array element has! It is still one element! Like first element of the vertex array is (0, 0, 0) and first element of the texture array is (0, 0).

Does OpenGL index by (what you define as) elements? I thought it was like this:
[…] bigarray[NumVertices3];
[…] bigarray2[NumNormals
3];
[…] bigarray3[NumTexCoords2];
If you want to access the Xth vertex, you have to give as position x
3 with vertices and normals, and x*2 with texcoords(assuming you have 3 coords per vertex+normal and 2 coords for a texcoord).

Originally posted by Hylke Donker:
Does OpenGL index by (what you define as) elements? I thought it was like this:
[…] bigarray[NumVertices3];
[…] bigarray2[NumNormals
3];
[…] bigarray3[NumTexCoords*2];

The OGL indexing is like:
struct { float x, y, z ; } bigarray[ NumVertices ] ;
struct { float x, y, z ; } bigarray2[ NumVertices ] ;
struct { float u, v ; } bigarray3[ NumVertices ] ;

Yup, just as Komat said

You should really read the spec :-/

Actually, i’ve read the specs, but I find it rather hard to bind plaintext with code. For example, I still haven’t found a definition of element in the specs of glDrawArrays, glVertexPointer etc.

Hm, it was pretty self-explanatory for me. Anyway, I am glad if we could help. Happy coding!