
Vertex Arrays ???
From readind the topics on this forum I've heard about vertext arrays and that they significantly speed up rendering. Rather thatn just calling glVertex for every vertex in a poly.
Well, I am ready to be enlightend. How do you work with vertex arrays. Please give a small example code or at least pseudo code.
[edited by - snisarenko on April 5, 2003 8:38:28 PM]

there is about 1 million articles on the internet detailing how to use vertex arrays in OpenGL. In fact, you''re posting this on the NeHe forums and i''m quite sure (although don''t quote me on this) that NeHe''s site contains a tutorial for using vertex arrays. So please try and help yourself first before asking for help.
GSACP: GameDev Society Against Crap PostingTo join: Put these lines in your signature and don't post crap!
Well, MelvinElvin, I''m sorry to say, you''re wrong. NeHe doesn''t have a tutorial on vertex arrays... Yet.
But all you need to know to use them is:
glVertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *array);
Where size is the number of coordinates for each vertex... Either 2, 3, or 4. And type is GL_DOUBLE, GL_FLOAT, GL_INT, GL_UNSIGNED_INT, GL_SHORT, GL_UNSIGNED_SHORT, GL_BYTE, or GL_UNSIGNED_BYTE.
stride is is the number of bytes between different vertices. If they are tightly acked in the array, this should be 0. And at last array is a pointer to the array of vertices.
and you need to know:
glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices);
mode is GL__POINTS, GL_LINE_STRIP, GK_LINE_LOOP, GL_LINES, GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN, GL_TRIANGLES, GL_QUAD_STRIP, GL_QUADS. count is the number of vertices to draw. type is either GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT. And indices is a pointer to the array of vertex indices. Note, that they are not asking for the vertices themselves, but the indices to the vertices!
Hope this helps.
But all you need to know to use them is:
glVertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *array);
Where size is the number of coordinates for each vertex... Either 2, 3, or 4. And type is GL_DOUBLE, GL_FLOAT, GL_INT, GL_UNSIGNED_INT, GL_SHORT, GL_UNSIGNED_SHORT, GL_BYTE, or GL_UNSIGNED_BYTE.
stride is is the number of bytes between different vertices. If they are tightly acked in the array, this should be 0. And at last array is a pointer to the array of vertices.
and you need to know:
glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices);
mode is GL__POINTS, GL_LINE_STRIP, GK_LINE_LOOP, GL_LINES, GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN, GL_TRIANGLES, GL_QUAD_STRIP, GL_QUADS. count is the number of vertices to draw. type is either GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT. And indices is a pointer to the array of vertex indices. Note, that they are not asking for the vertices themselves, but the indices to the vertices!
Hope this helps.
Thanks for the reply. One more question. How do you apply textures in vertes arrays ?
James, you forgot:
glEnableClientState( GL_VERTEX_ARRAY );
snisarenko,
If you want to do texture coords, or colors, or whatever, then you will need to do the same for them as you did for the vertex coordinates:
Then your choice of:
{
}
Use this page to help you out:
http://www.3dlabs.com/support/developer/glmanpage_index.htm
There's a little bit of a science to using vertex arrays (i.e. getting the "significant speed-up in rendering"), so I think you should try searching other places for some more "hearty" (i.e. deeper explanations) documentation. I read from the red book, the OpenGL 1.3 spec, tutorials from nVidia and ATi, and several of the extension specs that enhance these vertex arrays. Use the forum when you have a specific question.
[edited by - JONSKI on April 6, 2003 4:37:15 PM]
glEnableClientState( GL_VERTEX_ARRAY );
snisarenko,
If you want to do texture coords, or colors, or whatever, then you will need to do the same for them as you did for the vertex coordinates:
glEnableClientState( GL_TEXTURE_COORD_ARRAY );glTexCoordPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer );
Then your choice of:
{
glDrawArrays( GLenum mode, GLint first, GLsizei count ); glArrayElement( GLint i ); glDrawElements( GLenum mode, GLsizei count, GLenum type, const GLvoid *indices );
}
Use this page to help you out:
http://www.3dlabs.com/support/developer/glmanpage_index.htm
There's a little bit of a science to using vertex arrays (i.e. getting the "significant speed-up in rendering"), so I think you should try searching other places for some more "hearty" (i.e. deeper explanations) documentation. I read from the red book, the OpenGL 1.3 spec, tutorials from nVidia and ATi, and several of the extension specs that enhance these vertex arrays. Use the forum when you have a specific question.
[edited by - JONSKI on April 6, 2003 4:37:15 PM]
Interests: my money-pit car, computer hardware/programming, anything 3D'93 RX-7
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement