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 > Loading textures

#169541 - GugloPWN - Tue Jul 21, 2009 11:55 pm

My goal is to modify Payk's md2 loader so that the model and texture data is local to an object. Basically I wasn't happy how with Payks loader you have a global array of models and textures.

I got the models seperated but textures are not working correctly. I think I need a better understanding of the glCommands.

Code:
void LoadModelTexture(char filename[],int &Target,int &TargetPal,int* w)
{
//stuff here decodes the file into a buffer
   TargetPal = gluTexLoadPal( pal, 256, GL_RGB256 );
   glBindTexture (0, Target);
   if(width==64)glTexImage2D(0, 0, GL_RGB256, TEXTURE_SIZE_64, TEXTURE_SIZE_64, 0, TEXGEN_TEXCOORD|(3<<29),(uint8*)buffer8);
   if(width==128)glTexImage2D(0, 0, GL_RGB256, TEXTURE_SIZE_128, TEXTURE_SIZE_128, 0, TEXGEN_TEXCOORD |    GL_TEXTURE_WRAP_S |       GL_TEXTURE_WRAP_T,buffer8);
   free(buffer8);
}

I call the function like this
Code:
   glGenTextures(1, &Texture);
   LoadModelTexture(textfile,Texture,TexturePal,&textsize) ;

I am calling glGenTextures then LoadModelTexture upwards of 6 times, but it doesnt work for even the first. How does the code know where in VRAM to put the textures? I'd guess that the first call puts the texture at the beginning of bank A, does each subsequent call just pile the textures on after?

I've enabled banks A B and C for textures, will they automatically be used? glTexImage2D doesnt ask where in the VRAM it should put the textures so I have no idea where stuff is being written.

If someone can give me a good explanation of all this that'd be awesome.

#169543 - TwentySeven - Wed Jul 22, 2009 2:21 am

we need to see your glGenTexture calls.

#169544 - GugloPWN - Wed Jul 22, 2009 2:52 am

my objects each have members:
Code:
int Texture;
int TexturePal;
int textsize;

I loop through each object doing various non-GL things and calling
Code:
glGenTextures(1, &Texture);
   LoadModelTexture(textfile,Texture,TexturePal,&textsize) ;

I know its not something like the file isnt being found, because the textures are showing up, just wrapped around in strange ways. I know the UV coords of my models and the textures work because they looked fine before I altered the code, but I think the textures arent being loaded correctly, so I need to know more about VRAM.

#169545 - DiscoStew - Wed Jul 22, 2009 3:36 am

Code:
if(width==64)glTexImage2D(0, 0, GL_RGB256, TEXTURE_SIZE_64, TEXTURE_SIZE_64, 0, TEXGEN_TEXCOORD|(3<<29),(uint8*)buffer8);


Is there a reason why you have (3<<29) in your code? What that does if I'm correct is enables Color 0 transparency and sets TEXGEN_TEXCOORD, which you already have set.

Also, you have one setting to have texture wrapping, but not the other?
_________________
DS - It's all about DiscoStew

#169555 - GugloPWN - Wed Jul 22, 2009 11:09 pm

Stew, I have no idea what that line of code does, Im modifying Payk's md2 loader and getting problems. I understand some of the loader, all the code I've posted here is stuff that I don't understand.

From what I could gather TEXGEN_TEXCOORD just allows me to warp textures with a texture matrix if I was going for effects. My texture matrix is identity so that shouldnt do anything. I think my problem is that Im calling glGenTextures and glTexImage2D repeatedly in different places.

I want to be able to load up textures and models dynamically as I run around my game environment, rather than genning all the textures in one go at runtime like the loader originally did.

#169556 - TwentySeven - Thu Jul 23, 2009 12:04 am

The DS doesnt use normalized texture coordinates.

So, one issue is that the UVs for the model need to match the texture size. Are you accounting for this?

ie: UV built for 64x64 textures, you'll need to modify the texture matrix for it to map correctly to a 128x128

#169558 - GugloPWN - Thu Jul 23, 2009 2:53 am

I had models working correctly with textures and everything before trying to seperate out the texture variables from an array (int Textures[10]) to ten seperate (int Texture) in different objects. Im using a model that came with the example so I know it should work.

Is there any reason why I wouldnt be allowed to call glGenTextures more than once?

#169559 - DiscoStew - Thu Jul 23, 2009 3:20 am

GugloPWN wrote:
I had models working correctly with textures and everything before trying to seperate out the texture variables from an array (int Textures[10]) to ten seperate (int Texture) in different objects. Im using a model that came with the example so I know it should work.

Is there any reason why I wouldnt be allowed to call glGenTextures more than once?


Was it working with your current setup, but with an array of ints instead of a single int per object? If not, then it's somewhere else in your code that you made modifications to.

glGenTextures works multiple times (up until it reaches it's MAX_TEXTURE limit of 2400), and is reset completely with the use of glResetTextures.
_________________
DS - It's all about DiscoStew