View Full Version : vertex/texcoord/index/normal arrays
12-11-2002, 02:08 AM
I don't quite understand how to combine these arrays.
I know how to combine vertex and index arrays, but I don't quite see how to fit in the texcoord arrays.
What I'd like to do is define an object with arrays. But each polygon has shared vertexes. Defining one texcoord for each vertex is thus not possible. My book states OGL only gives ONE texcoord to each vertex.
Also, each polygon only has ONE normal. My book states that when OGL itterates over the arrays it gives each vertex ONE normal. I don't want this because vertexes are connected to several polygons (each poly with another normal)
Can someone explain to me how to pull this off (if possible at al), or can someone link me to a good extensive tutorial/article that combines all these arrays?
Vertex arrays in OpenGL does not have separate indeices for vertices, normals, textore corodinates and so on. If a shared vertex have two texture coordinates the vertex MUST be duplicated. Same with normals. If you want per face normals, you have to use the same normal for each vertex in the face. If you have shared vertices, you must even here duplicate vertices.
In OpenGL, a vertex in a vertex array is equal if, and only if, all it's components (coordinates, normals, texture coordinates, color) are equal. If a shared vertex differ in one single value, all of it's components must be duplicated.
but if you really don't like to duplicate vertices, there's a way around this: use glVertex/glNormal/glWhatever-calls.
12-11-2002, 03:22 AM
Tanks, you've answered my question and I understand it better now.
There is one more thing now:
What is faster?
Duplicating all vertices/texcoords is easilly done when loading the app but what is actuall faster during runtime?
1) giving all vertices/normals/etc with glvertex/glnormal/etc seperately
2) duplicating each vertex/normal/texcoord 3 or 4 or even more times (3 incase of a cube for example) and then give it one go to OGL in an array.
At which point is the array solution less profitable than the gl**** solution?
12-11-2002, 04:02 AM
Index arrays allow for reusing same veritces, thus there's no need for multiple copies of same verts belonging to different triangles.
This however doesn't let you have different, say texture coordinates on 2 neighbouring triangles, which in many cases is necessary.
12-11-2002, 04:25 AM
So basically the array solution is not suitable for more complex/detailed models?
Or one has to duplicate the vertices and give each one a different texcoord.
I've been thinking a tad about how many vertices you give to OGL, in for example a simple textured cube. In either case it's 24. Like you give 24 texcoords and 24 normals.
That makes me think of why people told me that vertex arrays were faster than giving each vertex/texcoord seperately to the OGL layer. In either case (when thinking back to the cube) OGL has to process 24 vertices, 24 texcoords and 24 normals. Which means it will calculate lighting for each vertice seperately. It will probably also calc translation seperately because the indexes of the array are different each time.
When I think about it, there is no speed gain when you define objects which share faces and have different texcoords, since the amount of calculations (for light and translation) are the same.
Or am I completely wrong here?
Is there any speedgain from changing to vertex arrays when you cannot "recycle" vertices?
12-11-2002, 04:46 AM
Best test it for your special purposes, it's pretty easy to make a little benchmark.
Once I played with MD2s (Quake 2 model format) I tested both rendering methods and although MD2s make use of same texture coordinates it was slighltly faster to convert it to arrays that could be rendered with glDrawArray(..) than one by one passing verts to OpenGL. I tried also display lists and they were over 2 times faster than vertex arrays http://www.opengl.org/discussion_boards/ubb/smile.gif
Powered by vBulletin® Version 4.2.2 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.