PDA

View Full Version : glDrawArrays



Hylke Donker
08-07-2006, 09:45 AM
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

zeoverlord
08-07-2006, 10:04 AM
Yes it's possible, the count value should be the number of vertics you have.

Relic
08-07-2006, 10:33 AM
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.

Hylke Donker
08-07-2006, 10:54 AM
Originally posted by Relic:
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. 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?

Zengar
08-07-2006, 12:06 PM
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 :-) You need no books on OpenGL except it.

Hylke Donker
08-08-2006, 03:05 AM
Originally posted by Zengar:
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 :-) You need no books on OpenGL except it. 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).

Zengar
08-09-2006, 01:26 PM
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).

Hylke Donker
08-09-2006, 01:40 PM
Does OpenGL index by (what you define as) elements? I thought it was like this:
[..] bigarray[NumVertices*3];
[..] bigarray2[NumNormals*3];
[..] bigarray3[NumTexCoords*2];
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).

Komat
08-09-2006, 02:13 PM
Originally posted by Hylke Donker:
Does OpenGL index by (what you define as) elements? I thought it was like this:
[..] bigarray[NumVertices*3];
[..] 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 ] ;

Zengar
08-09-2006, 06:01 PM
Yup, just as Komat said

You should really read the spec :-/

Hylke Donker
08-10-2006, 03:12 AM
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.

Zengar
08-10-2006, 03:23 AM
Hm, it was pretty self-explanatory for me. Anyway, I am glad if we could help. Happy coding!