PDA

View Full Version : glVertex3fv



kazmalak
01-05-2005, 02:44 AM
I started using OpenGL. I began reading the Redbook. In one of its examples, the glVertex3fv function is used. However, there is no explanation of how it can be used. What I have to write in the parenthesis after this function.
Can anyone explain clearly?

mikael_aronsson
01-05-2005, 05:01 AM
It wants a pointer to an array of 3 float values (x,y,z) for example:

GLfloat v[ 3] = { 0.0f, 0.0f, 0.0f };
glVertex3fv( &v[ 0]);

or GLfloat* v = ...
glVertex3fv( v);

It's just another way to pass the vertex corrdinates to OpenGL, it may be a little faster then using glVertex3f( v[ 0], v[ 1], v[ 2]);

Mikael

kazmalak
01-05-2005, 05:10 AM
I want to ask something more. What is the meaning of 0 in the below function you wrote.

glVertex3fv( &v[ 0]);

Similarly in the Redbook it is written

glVertex3fv(&vdata[tindices[i][0]][0]);
I understand the part [tindices[i][0]] but what is the meaning of the last zero.

kazmalak
01-05-2005, 05:12 AM
First thanks for your help .
I want to ask something more. What is the meaning of 0 in the below function you wrote.

glVertex3fv( &v[ 0]);

Similarly in the Redbook it is written

glVertex3fv(&vdata[tindices[i][0]][0]);
I understand the part [tindices[i][0]] but what is the meaning of the last zero.

Aeluned
01-05-2005, 05:16 AM
v[0] is the starting address of the array.
There, he is passing the array from the first element.

had he passed v[1], the function would have been given the array starting at the second index (most likely resulting in an error as OpenGL attempts to access the third vertex out of bounds).

v[0] would have been the same as v. that is, he could have passed glVertex3fv(&v) since when not specifying an index, the array name itself refers to the first index.

the second 0 you see in that other example is analogous, that's just a 2 dimensional array.

kazmalak
01-05-2005, 05:27 AM
Thanks all. I have really liked this site.

Omaha
01-05-2005, 07:07 AM
I'm sorry, I'm really sorry but I'm a perfectionist and things jump out at me. I'm very sure you caught this yourself but:



that is, he could have passed glVertex3fv(&v) since when not specifying an index, the array name itself refers to the first index.
Ahem:


glVertex3fv(v); // no address-of neededSince arrays are inherently addresses by name and all... :p

Aeluned
01-05-2005, 08:14 AM
right you are. :D