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 > How do I make a textured lit quad display list?

#151207 - BovineFury - Wed Feb 20, 2008 11:57 pm

I'm trying to make a group of textured quads that can be lit via a display list (glCallList()). How is it done? I've been trying to find some explanation of how this works, searched the forum, etc.

Is there anywhere I can go to find a tutorial on how this works? I've checked the devkitpro examples, but all it has is how to do a triangle with no normal or texturing.

I can't use a exporter because the list has to be generated in play.

#151208 - nce - Thu Feb 21, 2008 12:23 am

As soon as you have understood a to make a simple triangle with just position...

all other info works the same way you push vertices on your list. You can push normal and texture uvs too....

( you can even push your texture binding )
_________________
-jerome-

#151209 - BovineFury - Thu Feb 21, 2008 12:33 am

Is there any specific order that things are supposed to be pushed? Normal before texture, etc?

#151210 - BovineFury - Thu Feb 21, 2008 1:05 am

For that matter, is there anywhere that explains anything about how the display lists are set up?

From the devkit triangle example:
FIFO_COMMAND_PACK(FIFO_BEGIN, FIFO_COLOR, FIFO_VERTEX16, FIFO_COLOR). I see two color commands. Why?

Partway through the list is
FIFO_COMMAND_PACK(FIFO_VERTEX16, FIFO_COLOR, FIFO_VERTEX16, FIFO_END)

Why?

I've been running google searches and coming up with 4-5 results, none of which are any help. Is there any documentation that explains any of this?

#151215 - M3d10n - Thu Feb 21, 2008 2:14 am

BovineFury wrote:
For that matter, is there anywhere that explains anything about how the display lists are set up?


Do a search for "display lists" on this forum and you should find a thread which has nice info about them (I don't have the link myself, but I learned most of it there). But I'll try to help.


A display list is a large array of u32's. You basically have 4 commands packed into a single u32, followed by the data for each command. Different commands need different amounts of data, or no data at all.

BovineFury wrote:

From the devkit triangle example:
FIFO_COMMAND_PACK(FIFO_BEGIN, FIFO_COLOR, FIFO_VERTEX16, FIFO_COLOR). I see two color commands. Why?


The macro FIFO_COMMAND_PACK() packs four u8 command IDs into a single u32 value. I'll translate that command sequence to immediate mode so you can read it better:

Code:

1   glBegin();
2   glColor();
3   glVertex3v16();
4   glColor();


When drawing each geometry vertex, the position (FIFO_VERTEX16 or glVertex3v16() call) is always the last one for each vertex, so lines 2 and 3 in the example above define the first vertex. The 2nd glColor() command will be applied to the next vertex.

BovineFury wrote:

Partway through the list is
FIFO_COMMAND_PACK(FIFO_VERTEX16, FIFO_COLOR, FIFO_VERTEX16, FIFO_END)

Why?


Continuing from the previous commands...
Code:

5   glVertex3v16();
6   glColor();
7   glVertex3v16();
8   glEnd();

Line 5 ends the declaration of the 2nd vertex, then we have the 3rd vertex declared by lines 6 and 7. Line 8 closes the triangle.

Notice I didn't specify any parameters in the examples above. The command data is specified after the packed command. Here's a complete example:

Code:

u32 triangle[] =
{
   12,
   FIFO_COMMAND_PACK(FIFO_BEGIN, FIFO_COLOR, FIFO_VERTEX16, FIFO_COLOR),
   GL_TRIANGLE,
   RGB15(31,0,0),
   VERTEX_PACK(inttov16(-1),inttov16(-1)), VERTEX_PACK(0,0),
   RGB15(0,31,0),
   FIFO_COMMAND_PACK(FIFO_VERTEX16, FIFO_COLOR, FIFO_VERTEX16, FIFO_END),
   VERTEX_PACK(inttov16(1),inttov16(-1)), VERTEX_PACK(0,0),
   RGB15(0,0,31),
   VERTEX_PACK(inttov16(0),inttov16(1)), VERTEX_PACK(0,0),
};


This commands are executed in the following order:
Code:

FIFO_BEGIN
FIFO_COLOR
FIFO_VERTEX16
FIFO_COLOR
FIFO_VERTEX16
FIFO_COLOR
FIFO_VERTEX16
FIFO_END


Using immediate mode, it would look like this:
Code:

glBegin(GL_TRIANGLE);
glColor(RGB15(31,0,0));
glVertex3v16(inttov16(-1),inttov16(-1),0);
glColor(RGB15(0,31,0));
glVertex3v16(inttov16(1),inttov16(-1),0);
glColor(RGB15(0,0,31)); 
glVertex3v16(inttov16(0),inttov16(1),0);
glEnd();


The confusing thing is that FIFO_VERTEX16 needs two data entries (you can only fit two 16-bit coordinates in a u32), while all other commands in the example only require one. That's why there are always two VERTEX_PACK() calls next to each other: the first one defines the X and Y coordinates, and the 3rd one defines the Z coordinate (I'm not sure you can also set the W coordinate - never tested it).

Notice that the FIFO_END command has no data. When you understand that each command needs a different number of u32 data fields to work, dealing with display lists becomes much easier.

#151245 - BovineFury - Thu Feb 21, 2008 10:17 pm

Thank you. That was exactly what I needed to know. Texturing and normals are up and running.

#151255 - nce - Fri Feb 22, 2008 12:37 am

I've learn a lot when I started my exporter from 3dsmax in reading this :


http://nocash.emubase.de/gbatek.htm#ds3doverview
Geometry Commands (can be invoked by Port Address, or by Command ID) is the list of command you can use ( not all are working in display list I think ), and the number of parameter you'll have to send after.

and

http://nocash.emubase.de/gbatek.htm#ds3dgeometrycommands
explain you how to build a display list ( unpacked or packed as in the ndslib exemple )
_________________
-jerome-