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 > Problems with image8to16() in a Loading Texture function

#157622 - sUPREz - Tue May 27, 2008 10:24 am

Hi everyone. This is my first post. I'm new in DS dev.
I try to make a small game with a 3D ortho GUI.
I need to load several texture and I try to create a function that load a list of texture. Here is my code :

Code:
typedef struct tagTEXTURE
{
   char* name;
   GL_TEXTURE_SIZE_ENUM size_x, size_y;
   float x_reel, y_reel;
} TEXTURE;

const int numtexture = 3;
TEXTURE* textures_list;

void InitTextures()
{
   textures_list = (TEXTURE*)malloc(numtexture*sizeof(TEXTURE));

   textures_list[0].name = "Button00_pcx";
   textures_list[0].size_x = TEXTURE_SIZE_128;
   textures_list[0].size_y = TEXTURE_SIZE_64;
   //.75 means that my texture only use 96px of the 128px
   textures_list[0].x_reel = 0.75;
   //.75 means that my texture only use 48px of the 64px
   textures_list[0].y_reel = 0.75;

   
   
   textures_list[1].name = "Button01_pcx";
   textures_list[1].size_x = TEXTURE_SIZE_64;
   textures_list[1].size_y = TEXTURE_SIZE_64;
   textures_list[1].x_reel = 0.75;
   textures_list[1].y_reel = 0.75;

   textures_list[2].name = "Button02_pcx";
   textures_list[2].size_x = TEXTURE_SIZE_64;
   textures_list[2].size_y = TEXTURE_SIZE_64;
   textures_list[2].x_reel = 0.75;
   textures_list[2].y_reel = 0.75;
}

int LoadGLTextures()                           // Load PCX files And Convert To Textures
{
   InitTextures();
   int i;
   sImage pcx;

   for(i=0;i<numtexture;i++)
   {

      loadPCX((u8*)textures_list[i].name, &pcx);
      image8to16(&pcx);
      glGenTextures(1, &texture[i]);
      glBindTexture(0, texture[i]);
      glTexImage2D(0, 0, GL_RGB, textures_list[i].size_x , textures_list[i].size_y, 0, TEXGEN_TEXCOORD, pcx.image.data8);
      imageDestroy(&pcx);
   }
   return TRUE;
}


Everything works fine except the image8to16() function that make my ROM crash. I got "The rom-image has crashed" error message from no$GBA.
If I remove this line the program is running without problems but my textures are not loaded.
Can you give some help so I can't figure out where I'm wrong ? Thanks a lot.

EDIT : just a few word to say that I'm not using PA_lib.

#157624 - TwentySeven - Tue May 27, 2008 11:09 am

Are you sure your file system is working?
Are you sure loadPCX is working?

Have you checked whats in &pcx?

#157625 - sUPREz - Tue May 27, 2008 11:20 am

Yes this code is working if I'm loading my texture manually. Here is a previous working version of my code:

Code:

loadPCX((u8*)Button00_pcx, &pcx);
   image8to16(&pcx);
   glGenTextures(1, &texture[0]);
   glBindTexture(0, texture[0]);
   glTexImage2D(0, 0, GL_RGB, TEXTURE_SIZE_64 , TEXTURE_SIZE_64, 0, TEXGEN_TEXCOORD, pcx.image.data8);
   imageDestroy(&pcx);


Meanwhile, I don't check what is in &pcx. I'll check this but as I don't have the debug version of no$gba, it's a little bit harder.

#157627 - Maxxie - Tue May 27, 2008 11:40 am

Quote:

Code:

 loadPCX((u8*)textures_list[i].name, &pcx);



should be the one causing troubles.

loadPCX expects a pointer to the image (a memory location containing the file content) not a filename.

#157631 - sUPREz - Tue May 27, 2008 1:13 pm

Thanks !
You're right!

I modified my structure :

Code:
typedef struct tagTEXTURE
{
   u8* name;
   GL_TEXTURE_SIZE_ENUM size_x, size_y;
   float x_reel, y_reel;
} TEXTURE;


and change my structure allocation :

Code:
   textures_list[0].name = (u8*)Button00_pcx;
   textures_list[0].size_x = TEXTURE_SIZE_128;
   textures_list[0].size_y = TEXTURE_SIZE_64;
   textures_list[0].x_reel = 0.75;
   textures_list[0].y_reel = 0.75;


And it works. I now have some graphics issues but it's another problem I think :)

Thanks Maxxie.