Subscribe to The Crispy Blog        RSS Feed

DS Homebrew Development - Part 1

Icon Leave Comment
I have made a good start to my DS development framework. The first task I decided to tackle was how to load in files from an external location on the DS card I am using (R4DS). Libnds has a way of packing the files in with the executable which is relatively easy but has a maximum of around 100kb of memory to use, in other words not very much at all when it comes to mesh files, textures and sounds.

Luckily it comes packaged with a library call libFAT which enables use of most of the functions found in the stdio header for reading and writing files. Using this to load in textures seemed to be my only option, so I modified my OpenGL RAW texture loading function to use libnds' PCX image loading function.

The finished result:

static int LoadDSTexture( const char * filename, int width, int height)
   int texture;
   sImage pcx; // this is the libnds type that is filled using the loadPCX function
   void* data; // this is a pointer to a memory location which the file will load and point to 
   FILE * file;

   // open texture data
   file = fopen( filename, "rb" );
   if(file == NULL) { std::cout << "cannot open texture file:" << filename << "\n"; }

   // allocate buffer
   data = malloc( width * height * 3 );

   // read texture data
   fread( data, width * height * 3, 1, file );
   fclose( file );

   loadPCX((u8*)data, &pcx); // create a texture, pass in a pointer to the memory location of the pcx data and the sImage file to fill.


   // allocate a texture name
   glGenTextures( 1, &texture );
   // select texture
   glBindTexture( GL_TEXTURE_2D, texture );
   glTexImage2D(0, 0, GL_RGB, TEXTURE_SIZE_128 , TEXTURE_SIZE_128, 0, TEXGEN_TEXCOORD, pcx.image.data8);

   // free buffer

   return texture;

It does the trick and PCX files have such a small file size. Next the class design revealed :)

0 Comments On This Entry


September 2018

161718192021 22

Recent Entries

Search My Blog

0 user(s) viewing

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