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 > Troubles loading multiple textures

#176202 - SchmendrickSchmuck - Sun May 08, 2011 3:50 am

Hi all,
I'm using a function to easily load a texture into memory. However, as soon as I load more than a single texture, the textures other than the first all become white when displayed.

My code regarding the textures:
Loading
Code:

numTextures++;

glGenTextures(1, &gltextures[numTextures]);
glBindTexture(0, gltextures[numTextures]);
glTexImage2D(0, 0, GL_RGBA, eWidth, eHeight, 0, TEXGEN_TEXCOORD, textureData);

return numTextures;


Displaying:
Code:

glBindTexture(GL_TEXTURE_2D, gltextures[texture]);
glBegin(GL_QUADS);
//... etc


gltextures is a int[MAX_TEXTURES], where MAX_TEXTURES is defined as 2048 in video_gl.h.
eWidth and eHeight are values calculated based on texture size, and can be assumed to be correct.
Data is also fine, as the textures are displayed correctly when loaded first.

I've compared my code to all the examples I could find, but I can't find the answer. If it's not this part of the code, perhaps it's impossible to load multiple pcx files?

Code:

sImage pcx;

loadPCX((u8*)tex, &pcx);

image8to16trans(&pcx, transCol);

// Load as texture
[....]

imageDestroy(&pcx);


Any thoughts?
Thanks
_________________
http://DSLiero.DennisvanZwieten.com - Liero for NDS!


Last edited by SchmendrickSchmuck on Wed May 11, 2011 11:39 pm; edited 2 times in total

#176203 - DiscoStew - Sun May 08, 2011 9:31 am

Have you tried using textures that are not of PCX format to see if the problem is with the loading functions? I couldn't duplicate your problem with the Paletted_Cube example. If after testing that out, and it still has a problem, then could you provide a trimmed-down version of your program that continues to replicate this problem so we can analyze it? I did the work of libnds's dynamic texture allocating, so I should be able to provide a fix if the allocator is the problem.

If that isn't the problem, then it must be something else. What are the dimensions of the PCX files? If they are big, are you allocating enough video memory (A-D banks) to hold them?
_________________
DS - It's all about DiscoStew

#176206 - SchmendrickSchmuck - Sun May 08, 2011 12:26 pm

It does appear to be a memory issue; Loading a smaller texture seems to work.

The main reason is (I think) that the textures are converted to 16bit RGB.
I switched over to paletted textures, and that seems to work. However, transparency doesn't work anymore. Is it possible to have transparency in RGB256 color textures?

EDIT:
Nvm, it seems you can only set color 0 as transparent with the GL_TEXTURE_COLOR0_TRANSPARENT when using paletted textures. Thanks for pointing out the memory issue.

EDIT 2:
I can load two paletted textures, but in doing so my palettes get messed up, and the color tables for the textures become incorrect. Loading a 4 color palette before my main palette causes a shift in palette entries, making the texture look off. See piccy below for example.

http://temp.dennisvanzwieten.com/palettes.png

Also, is there any way of directly modifying texture palette data so that if I change the value, the texture immediately mirrors the change?
_________________
http://DSLiero.DennisvanZwieten.com - Liero for NDS!