Advertisement

vertex array example

Started by August 22, 2001 04:25 AM
11 comments, last by penetrator 23 years, 6 months ago
Hi guys, i found some examples about vertex arrays but i don''t understand how they work. Could somebody help me ? glHorizon_Project

www.web-discovery.net

You can read information about vertex-array in Redbook.
I have written some simple programs with vertex-array.
If you interest in my source codes, let me know

bondi


Advertisement
well, what don''t you understand about them? The theory, or the implimentation? You basically create an array with all of your verticies. We''ll call ''v'' our array. v[0] is x1, v[1] is y1, and [2] is z1. Then for each successive triangle you just keep going, v[3] is x2, v[4] is y2, v[5] is z2. Then you tell OpenGL where to look for the array using glVertexArrayPointer(), I think, Then you can use glDrawArrays or glDrawElements to render your stuff. I''m not sure about that first function name, and I''m at work so I can''t check, but that''s basically what you do.



How many Microsoft employees does it take to screw in a light bulb?
None, they just declare drakness as a new standard.
My HomepageSome shoot to kill, others shoot to mame. I say clear the chamber and let the lord decide. - Reno 911
Infact it is what i''m trying to do. As you can see below, i''m trying to build a 256x256 grid, but when i run the code i get only a blank screen, and i can''t see where is the error.

float vertices[2*256*3];
int p;
glLoadIdentity();
glRotatef( tilt, 1.0, 0.0, 0.0 );
glRotatef( heading, 0.0, -1.0, 0.0 );
glTranslatef( xpos, ypos, zpos );
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3,GL_FLOAT,0,vertices);
for ( y=0; y<256; y++)
{
for ( x = 0; x<256; x++)
{
p=0;
vertices[p++]=x;
vertices[p++]=(y+1);
vertices[p++]=3;
vertices[p++]=x;
vertices[p++]=y;
vertices[p++]=3;
glColor3f(1,1,1);
glDrawArrays(GL_TRIANGLE_STRIP, 0, p/3);
}
glEnd();
}


glHorizon_Project



www.web-discovery.net


I think the idea is that you draw your vertices all at once after you''ve completely filled the array, not as you go about filling it up.

-Mezz
well, for one thing you''re starting on the first element of the array instead of the 0th element. instead of p++ try ++p.



How many Microsoft employees does it take to screw in a light bulb?
None, they just declare drakness as a new standard.
My HomepageSome shoot to kill, others shoot to mame. I say clear the chamber and let the lord decide. - Reno 911
Advertisement
oh, and you shouldn''t reset p to zero each pass. you should set it to 0 before the for loops.



How many Microsoft employees does it take to screw in a light bulb?
None, they just declare drakness as a new standard.
My HomepageSome shoot to kill, others shoot to mame. I say clear the chamber and let the lord decide. - Reno 911
Hi Julio, i tried but doesn''t work yet. Bah !

glHorizon_Project



www.web-discovery.net


I was just talking to illuzion on this topic last week. See the post by illuzion on "using vertex arrays" . I have elaborated the steps on using vertex arrays in my reply to that post.
NeoGL
GL_TRIANGLE_STRIPS should work, but does it work if you use GL_TRIANGLES instead?



How many Microsoft employees does it take to screw in a light bulb?
None, they just declare drakness as a new standard.
My HomepageSome shoot to kill, others shoot to mame. I say clear the chamber and let the lord decide. - Reno 911

This topic is closed to new replies.

Advertisement