PDA

View Full Version : Interleaved arrays and static data and not getting any!



TheGecko
01-28-2001, 06:23 PM
OK I'm a little confused right now.It's 2:00am,I'm hungry,my code keeps crashing and I'm not getting any love from my woman so bear with me while I try to explain my problem.Here goes.

I've recently finished writing an exporter plugin for 3DS MAX and it exports the mesh data in the following format:




//-------------------------------------------------------------------
typedef struct
{
int v1,v2,v3; //the indices to the 3 vertices

}BMF_Face;
//-------------------------------------------------------------------
typedef struct
{
float u,v; //Texture coordinates
float nx,ny,nz; //normals
float x,y,z; //position

}HeavyVertex;
//-------------------------------------------------------------------
typedef struct
{
DWORD ID; //The magic number of our BMF file format.Should be (0x8A8A)
int Animated; //This file also includes animation info.(1=yes,0=no)

WORD numVertices;//The number of vertices in our mesh
WORD numFaces; //The number of faces in our mesh

HeavyVertex *Vertices; //Pointer to the vertices
BMF_Face *Faces; //Pointer to the list of faces

}BMFMesh;
//-------------------------------------------------------------------


Basically,my file format has a magic id number,a flag to indicate whether animations are included,the number of vertices and faces in the file and finally,a pointer to the actual vertices and the faces.
So,now that we know what's in the file,here's my question:

For static data (ie there are no animations included.All I will be doing with the mesh is rotating and translating it) like a house or a spaceship,what is the best and fastest way to actually draw the damn thing?

What I did was create an interleaved array with a format of GL_T2F_N3F_V3F for the vertices with 0 bytes for the stride.So my Interleaved array statement would look like this:




glInterleavedArrays(GL_T2F_C4F_N3F_V3F,0,mesh->Vertices);


Right after that,I would create a display list like this:




glNewList(Model,GL_COMPILE);
glDrawElements(GL_TRIANGLES,mesh->numFaces*3,GL_UNSIGNED_INT,mesh->Faces);

glEndList();


The I would simply call this display list whenever I want to render it.

Now am I doing something really stupid or inefficient?This code actually renders my object,but I just want to know if there is a better way of doing it (I heard of CVA's but one look at those and my life just got alot more complicated due to this whole locking/unlocking thing) So,before I go totally insane,what are the methods pros use (or nVidia engineers recommend) to do just this.(do remember that I will be translating,rotating and scaling this model in my world)

phew! Now where's my Mountain Deeeewwww..zzzzzzz.....

MojoMagic
01-28-2001, 07:06 PM
If your geometry is completely static you can't go past a good display list. They're easy to use, reliable and pretty much hands-down the fastest option.

You'll still be able to translate/rotate your object. But I don't think you'll be able to scale it. Though if anyone knows of a way I'd love to hear about it.
I guess it migt be possible through a matrix multiply. hmmm. Now that I think of it scaling might very well be possible. I'll have to try it.

If your geometry is not going to be modified (ie: spinning teapot etc), there is really NO reason to use anything other than a display list... I believe this is also the IHVs opinion on the matter.

TheGecko
01-29-2001, 11:14 AM
Oh,so basically I should construct my model in a display list by using a loop and just using the glVertex3f() command and manually construct the triangle? Well...if display lists are as optimised as you say then I have nothing to worry about http://www.opengl.org/discussion_boards/ubb/smile.gif

Michael Steinberg
01-29-2001, 11:48 AM
It is possible to scale them (In my OpenGL book they specify a cube and rotate/translate/scale it).