View Full Version : Creating models suitable for vbo's

08-08-2005, 11:10 AM
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 -.-

08-08-2005, 01:28 PM
You have to convert model dataset to indexed format. For example, let your model have following arrays:
1. array of vertices (vec3)
2. array of normals (vec3)
3. array of texcoords (vec2)
4. array of N faces in format Vi/Ni/Ti Vi/Ni/Ti Vi/Ni/Ti

5. create array of newvertex (vec3, vec3, vec2)
6. create array of newfaces (int p[3])

pseudocode looks like:

typedef struct tagnewvertex
vec3 pos;
vec3 norm;
vec2 tex;
} newvertex;

typedef struct tagnewface
int p[3];
} newface;

for (int i=0; i<numfaces; i++)
face* f = faces[i];
newface nf;
for (int j=0; j<3; j++) // assume triangles only
newvertex nv;
// 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&amp; nw);

// just add new vertex
void AddNewFace(newface&amp; 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...


08-08-2005, 10:46 PM
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 :D

08-09-2005, 12:09 AM
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