PDA

View Full Version : Create vertices indices



MacPC
06-05-2009, 04:35 AM
Hi, I am a newbie to OpenGL. I am learning to use the glDrawElements function. Using Blender, I have made a vertices of a somewhat complicated shape, but now I am stuck because I don't know how to make the indices array of the vertices. It seems impossible to do it by hand, is there some special software that can generate the indices?

Another question is kinda related, how do I made the Normal vertices?

Thanks in advance.

dletozeun
06-05-2009, 05:29 AM
There is no concept of vertex indices exposed to artists in a any modeler like Blender. It just a convenient way to represent mesh data to render it efficiently.

Basically, when you create a mesh you have an array of vertices, triangles, normals, etc. It happens that lots of triangles use the same vertices and to prevent many vertex duplications, array of indices are used. These arrays are used to index vertex data and allow less memory consumption.

I advise you to just read any 3D file and you will understand what are indices and how to use them. You may read a obj file which is the simplest file format I think.

MacPC
06-05-2009, 06:18 AM
Hi dletozeun,

thanks for the reply. I do understand the concept of the shared vertices. I am just very confused with how the indices is generated, for example, I have the famous teapot model, it clearly has three parts - a vertices array, a normal array and a indices array.

Like you said, I have my object in a obj file. A look at this link http://www.royriggs.com/obj.html seem to shed some light. In the obj file, I understand that v is the vertices, vn is the normal, but f, that's got to be the indices, am I correct? If that's the case it will be really easy to write a program to convert it to and index array.

Thanks again.

_NK47
06-05-2009, 06:28 AM
the indices can be generated in many ways. model tools just export the file and generate those indices for you. you can rearrange then for better cache optimization so how they are generated is not really important imho.

f stands for a term called "face" which references the triangle with the difference that a triangle has 3 vertices whereas a face can have more.

MacPC
06-05-2009, 06:56 AM
I think I finally got it!! the the first digit of the f is indeed the index! :)

Thank you all.

_NK47
06-05-2009, 07:17 AM
the index of the first vertex! f.e. "f 100, 101, 99" is the 100th, 101st and 99th vertex of your vertex list describing a triangle (or face in this context).

code would look something like that:
vector3* vertex_array;
vector3 vertex1 = vertex_array[100];
vector3 vertex2 = vertex_array[101];
vector3 vertex3 = vertex_array[99];