the model formats i looked at so far store the vertex data i different arrays, e.g. the .obj file format has an array of vertices (i.e. positions), one of vertex normals and one for texture coordinates. then there’s a forth array which holds index pairs. these can then be used in an engine to select the correct data. this is easy to do in immediate mode, but now i’m using vbo’s and i can only have one single array of indices. so i have to duplicate some data to create a set of unique vertex data.
my question is, how do YOU convert your model data from the sources into data suitable for vbo’s? so far i only have a cube model (which i manually converted from an obj. file into a fitting format) to test my code… ^^ or is there also an existing model format which saves its data in a way that would work fine?
thanks in advance and as always sry if i misunderstood sth -.-
You have to convert model dataset to indexed format. For example, let your model have following arrays:
array of vertices (vec3)
array of normals (vec3)
array of texcoords (vec2)
array of N faces in format Vi/Ni/Ti Vi/Ni/Ti Vi/Ni/Ti
create array of newvertex (vec3, vec3, vec2)
create array of newfaces (int p)
pseudocode looks like:
typedef struct tagnewvertex
typedef struct tagnewface
for (int i=0; i<numfaces; i++)
face* f = faces[i];
for (int j=0; j<3; j++) // assume triangles only
// collect all information for newvertex
nv.pos = vertices[f->v[j]];
nv.norm = normals[f->n[j]];
nv.tex = texcoords[f->t[j]];
// try to find index if such vertex already exist or just add this vertex and return it's index
nf.p[j] = AddOrFindNewVertex(nv);
Implement following functions...
// input is newvertex
// returns index of existing or added vertex
int AddOrFindNewVertex(newvertex& nw);
// just add new vertex
void AddNewFace(newface& nf);
Now, you can copy array of newvertices and array of newfaces into VBO, setup correct pointers and render model using glDrawElements call
This is most easiest solution. You may try to make strips instead of triangle list, or reorder vertices to maximize GPU vertex cache…
ok that’s what i planned to do, too. thought there would be an easier way and i’m compicating things too much
You may try to make strips instead of triangle list, or reorder vertices to maximize GPU vertex cache…
do you know of some good sources on how to convert model data into triange strips? i once read about some converter, but it was commercial. well i should google once again i guess ^^ and how could i reorder my data so that it works more effective?
thanks so far
you order vertices the way the indices use them.
like it would be bad to have indices
98 99 100 next to 1 2 3
as you jump a lot in your vertex memory.
nvtristrip is a free library from nvidia available at their website, there is also a couple of others which are faster