Subscribe to The Crispy Blog        RSS Feed
-----

DS Homebrew Development - Part 2

Icon Leave Comment
So after the success of my texture loading function I decided to try and load some meshes onto the DS. I already had some model loading classes I could convert to load files from the DS. First I needed to change my file loading class to use libnds' file loading library. This turned out to just be a case of changing the C++ code to straight C code.

I won't bore anyone with my file loading code as its pretty straightforward. So now due to the very OpenGL like code used in libnds there were only minor changes needed to get my model loading classes to work on the DS. So I load a mesh into the DS and its only drawing half of the mesh, turns out the DS can only handle around 2000 triangles at any time. There is also the fact that the current drawing code for the mesh is pretty inefficient.

int numTris = tris.size();
glBegin(GL_TRIANGLES); 
for (int i = 0; i < numTris; i++)
{
   const Tri& tri = tris[i];
   for (int j = 0; j < 3; j++)
   {
      const Vert& vert = tri.m_verts[j];
  
      glTexCoord2f(vert.m_u, vert.m_v);
      glNormal3f(vert.m_nx, vert.m_ny, vert.m_nz);
      glVertex3f(vert.m_x, vert.m_y, vert.m_z);
   }
 }
glEnd();



In OpenGL there is a way to draw a lot more efficiently and it is using Vertex Arrays which can be streamed from a buffer just like DirectX.
A bit of research and I realise that libnds doesn't have this option :( A little more research and I come across libnds' answer to display lists, its horrible:
//display list
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),
};



As you can probably imagine trying to make anything more complicated than a triangle with this structure is going to be error prone and just plain mind numbing. So I have decided to hide all this in a class to make things a little nicer.

class DisplayList
{
public:

	DisplayList(int listSize);

	void AddBeginPack();
	void AddEndPack();
	void AddPack();

	void End();

	void AddVertex(float x, float y, float z);
	void AddVertexColour(int r, int g, int b);

	u32* list;

	u32* tempList;

private:

	int m_listSize;
	int m_listCount;
	int m_tempListCount;
};



Much nicer :) but there are still some parts I need to iron out.

0 Comments On This Entry

 

August 2014

S M T W T F S
     12
3456789
10111213141516
1718192021 22 23
24252627282930
31      

Recent Entries

Search My Blog

0 user(s) viewing

0 Guests
0 member(s)
0 anonymous member(s)