gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > Most efficient method of rendering huge polygons?

#123391 - adzz182 - Tue Mar 27, 2007 9:40 pm

I am quite new to openGL programming, I know there are many different methods of rendering polygons. As the DS is no processing powerhouse, could someone please explain to me the most resource efficient method.

Right now i am using Blender 3D for Mac OSX to create my 3D environment, i found a partially DS compatible plugin for Blender (which i am currently editing to make it more efficient) which exports your polygon as a long series of glVertex / glNormal calls
Code:

Eg,

glBegin(1);
      glNormal3f(0.257637, 0.417096, 0.871548);
      glVertex3f(0.750000, -1.000000, -0.000000);
      glNormal3f(0.257546, 0.488174, 0.833857);
      glVertex3f(0.873768, -0.997926, -0.068859);
      glNormal3f(0.210730, 0.194952, 0.957884);
      glVertex3f(0.872332, -0.870509, -0.149090);
      glNormal3f(0.287729, 0.279122, 0.916105);
      glVertex3f(0.749025, -0.873358, -0.054499);
glEnd();
glBegin(1);
etc
etc
etc

Is this an efficient was of drawing polygons, or is using Vertex arrays or maybe Height Maps better?

Thanks alot

#123399 - simonjhall - Tue Mar 27, 2007 10:09 pm

That isn't the best way of doing it, as those are the floating-point wrapper functions, and the DS has no floating-point unit.
A better way is to convert (offline, or at load time) all your floating-point vertices and normals to the fixed-point format used by the DS.

For instance, the DS vertex format that I use (look http://nocash.emubase.de/gbatek.htm#ds3dpolygondefinitionsbyvertices for more details) is the 4.12 fixed-point format. So when I load all my verts I multiply them by 4096 to get them into this format, then truncate them to ints.

Then when it comes to actually doing the glVertex3f call I do this:
Code:
#define GFX_BEGIN         (*(volatile unsigned int *) 0x04000500)
#define GFX_VERTEX16          (*(volatile unsigned int *) 0x0400048C)
#define DS_BEGIN_TRIANGLE() GFX_BEGIN = 0
#define DS_VERTEX3V16(x, y, z) GFX_VERTEX16 = (y << 16) | (x & 0xFFFF); GFX_VERTEX16 = ((unsigned int)(unsigned short)z)

....
DS_BEGIN_TRIANGLE();
DS_VERTEX3V16(vert_x, vert_y, vert_z);
DS_VERTEX3V16(vert_x2, vert_y2, vert_z2);
DS_VERTEX3V16(vert_x3, vert_y3, vert_z3);
...
etc. This way you don't need to do expensive fp stuff per-tri.
There's no need for a glEnd().
There are also (native) fixed-point versions of glTexcoord2f and glNormal3f. Read that web page :-)
_________________
Big thanks to everyone who donated for Quake2

#123400 - silent_code - Tue Mar 27, 2007 10:24 pm

plus, you will have your models hardcoded inside the executable and that is not what you want in the long term. btw: don't mix up opengl with libnds' gl. it's similar, but not fully compatible.

you better store your models in some file format and write a rendering routine that takes a set of vertex/primitive (triangle, quad whatever) data (a mesh) and displays it. or you export the meshes to native nds display list binaries. you decide.


Last edited by silent_code on Sun Apr 01, 2007 6:33 pm; edited 1 time in total

#123442 - ikaris - Wed Mar 28, 2007 6:20 am

silent_code wrote:
you better store your models in some file format and write a rendering routine that takes a set of vertex/primitive (triangle, quad whatever) data (a mesh) and displays it. or you export the meshes to native nds display list binaries. you decide.


Though it depends upon what you're after, I would personally recommend the former (rendering routine). That's what I'm doing now since it allows me to do UV animation, skinning, etc...

However, if you want to generate a display list and you can get your hands on a copy of Maya, you can use my Display List Exporter:

http://www.vurtx.com/tools/dlDSDisplayListExporter.zip

#123890 - M3d10n - Sun Apr 01, 2007 5:10 am

Hey, Ikaris, why don't you give the FBX SDK a look?

I believe your exporter would become more widely used if you created a FBX-to-DSdl converter. You'd support many programs in a single strike, since most big apps can export FBX files (with the glorious exception of Blender, it seems.)

You could also try the Collada SDK.