PDA

View Full Version : Drawing Vertex Arrays

ImpactDNI
10-18-2002, 09:09 AM
Well... I have about 2 pages of code of glVertex3fv(vx) where x is a #... and a list of like 10 verticies...
i want to shorten this to 3 arrays... one array has the 10 verticies... one array has the order i want them drawn in for 6 quads... and the last array has the order i want them in to draw 8 triangles...

static GLfloat vertex[10][3] = {{-1.5, 1, 1.5}, {1.5, 1, 1.5}, {1.5, 1, -1.5}, {-1.5, 1, -1.5}, {0, 2, 0}, {0, -2, 0}, {-1.5, -1, 1.5}, {1.5, -1, 1.5}, {1.5, -1, -1.5}, {-1.5, -1, -1.5}};

static GLint quadorder[6][4] = {{1,2,3,4}, {7,8,9,10}, {1,4,10,7}, {1,2,8,7}, {2,3,9,8}, {3,9,10,4}};
static GLint triorder[8][3] = {{1,2,5}, {2,3,5}, {4,3,5}, {1,5,4}, {7,8,6}, {8,9,6}, {10,9,6}, {7,6,10}};

Anyhow, is there a way for me to have it draw each triangle (based on the numbers in triorder, and all quads based on the numbers in quadorder)? could you please give me an example??
Thanks a bunch
-Impact

ImpactDNI
10-18-2002, 09:11 AM
I thought i had it simplified to (inside a begin/end)
for (int h = 0; h < 2; h++){
for (int g = 0; g < 4; g++){
}
}

but it draws really bad shapes (not the ones i want)..... if it worked, it should draw a cube with points on the top/bottom

coredump
10-18-2002, 09:26 AM
change your call to glVertex3fv to look like this:

the 3fv in glVertex3fv states that you need to pass the address of an array of 3 floats. in your example, you are passing in the address of a float. and since you indexed it at 3, it's actually getting the vertex _after_ the one you really want.

b

ImpactDNI
10-18-2002, 09:32 AM
i thought that too... but i tried it without the [0], and its still got retard-o draws...

ImpactDNI
10-18-2002, 09:37 AM
sry, that 2nd post i had.. it was originally [0]... i had it switched to [3] when testing to see if i could fix it... it was [0]... but dropping the [0] doesn't work...

nexusone
10-18-2002, 10:46 AM

glVertex3fv( &vertex[X])

I used this on my vertex array's so I know it works, if it look's screwed then the data is in the wrong order or something.

As you know we process three points for triangles, and four for quads.

glBegin( GL_?????)
for (i=0; i < number_of_blanks; i++)// blanks is total tri's or quads.
{
for (j=0; j < number_sides; j++) // sides is 3 or 4, but remember we start with zero, so 3 becomes 2, and 4 becames 3.
{
glVertex3fv( &vertex[j+(i*number_sides)]);
}
}
glEnd()

Note most is from my head, but think this is correct.

Originally posted by coredump:
change your call to glVertex3fv to look like this:

the 3fv in glVertex3fv states that you need to pass the address of an array of 3 floats. in your example, you are passing in the address of a float. and since you indexed it at 3, it's actually getting the vertex _after_ the one you really want.

b

ImpactDNI
10-18-2002, 07:24 PM
Tonite it hit me... before i saw this post, but thanks a ton anyhow man... 1 = 0... when i transfered my points from v1[3] = (x,x,x), v2[3] = (x,x,x), and so on, i forgot to replace the numbers of the ones drawn... it was drawing 1,2,3 points in the array... but my old v1, was now vertex[0][]... v1 moved to 0.... and 2 to 1 and so on... just gotta fix that... thanks a ton for yer help guys
Thanks a ton
-Impact

M/\dm/\n
10-21-2002, 11:13 PM
Try using glDrawArrays(), glDrawElements() and there was also function for indices. Speeds the work a lot!!