Archived

This topic is now archived and is closed to further replies.

Lanman

Vertex arrays ?

Recommended Posts

Lanman    122
Hi there ! I''ve heared something about vertex arays. Is it faster ? I guess so. So, I need to know how to do it... I''ve read (in this forum some time ago) that its not good (and fast) to call glVertex3f may times. I don''t know what vertex array looks like. I imagine that it would look like normal array. But i don''t know how to tell OpenGL to draw vertexes from this array. I''ve tried to find something looking like this in gl.h but i didn''t find anything. I imagine that the command would look like glVertexnf( ... ). I just don''t know how to do it...please help me.Send me any www or good tut how to do it. Thanks !!!

Share this post


Link to post
Share on other sites
Fritz3D    122
I can''t understand one thing about vertex arrays:

can I use them for drawing for instance several cubes with non-smooth sides? All I have read says they are good for tristrips and nothing more.

Share this post


Link to post
Share on other sites
invective    118
quote:

can I use them for drawing for instance several cubes with non-smooth sides? All I have read says they are good for tristrips and nothing more



Yes. You can use them to draw GL_POINTS, GL_LINE_STRIP, GL_LINE_LOOP, GL_LINES, GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN, GL_TRIANGLES, GL_QUAD_STRIP, GL_QUADS, and GL_POLYGON.

Do not share vertex normals along edges for faceted things like cubes. Use 2 GL_TRIANGLES or 1 GL_QUADS per face, instead of sharing vertices with GL_TRIANGLE_STRIP or GL_QUAD_STRIP.

Share this post


Link to post
Share on other sites
Lanman    122
Thanx!!!
Well, finaly I know the command to draw the array...BUT there''s one more thing that I don''t know...how to set up the array (sorry for the newbie question...I''m not a newbie, I''m programming sice my 10 years but I''m triing to work with OpenGL for only less than year)...where can I find an example code...PLEASE...THANX!THANX!THANX! You are probably pissed off when you see every day my new stupid question, huh ?
But thanx !

Share this post


Link to post
Share on other sites
Null and Void    1088
To draw a square (with an extra z coordinate for no reason):
  
float Data[] = { -1.0f, -1.0f, 0.0f,
-1.0f, 1.0f, 0.0f,
1.0f, 1.0f, 0.0f,
1.0f, -1.0f, 0.0f };

glVertexPointer(3,GL_FLOAT,0,Data);
glDrawArrays(GL_QUAD, 0, 1);

You should also lookup glEnableClientState and glDisableClientState (I forgot about them last time) to use more than just vertices (i.e. to add textures, colors, or normals).

Share this post


Link to post
Share on other sites
Fritz3D    122
quote:
Original post by invective
Yes. You can use them to draw GL_POINTS, GL_LINE_STRIP, GL_LINE_LOOP, GL_LINES, GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN, GL_TRIANGLES, GL_QUAD_STRIP, GL_QUADS, and GL_POLYGON.

Do not share vertex normals along edges for faceted things like cubes. Use 2 GL_TRIANGLES or 1 GL_QUADS per face, instead of sharing vertices with GL_TRIANGLE_STRIP or GL_QUAD_STRIP.



K, but this means a lot of redundant glVertex and glNormal etc, is it still faster than a display list?

Share this post


Link to post
Share on other sites
Myopic Rhino    2317
quote:
Original post by Fritz3D
K, but this means a lot of redundant glVertex and glNormal etc, is it still faster than a display list?

If you''re drawing anything with hard edges (like a cube), you really have no choice but to duplicate some verticies, whether you''re using display lists or vertex arrays.

I''m not really sure what you''re asking, though, because when you''re using vertex arrays, you''re not making calls to glVertex/glNormal at all. The main advantage to vertex arrays is avoiding the overhead of calling those functions repeatedly.

Also, you can place your vertex array code in a display list.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
how do you fill a vertex array to use with opengl with linked lists or someother nonstatic data structure?

Share this post


Link to post
Share on other sites
outRider    852
Vertex arrays expect just what they''re named for, arrays. malloc however many vertices you have in your list and traverse the list and copy the vertices to the array.

------------
- outRider -

Share this post


Link to post
Share on other sites