Page 1 of 1

Textures directly from files

Posted: Wed Jun 16, 2010 4:04 pm
by Lin
Is there a way to load textures from a file at runtime? I tried to modify the "neheGX" example number 6 to use TPL_OpenTPLFromFile instead of TPL_OpenTPLFromMemory, but simply switching the function calls and removing the nehe-related header files produced only a black screen and inert machine. (I put the file NeHe.bmp both in the same directory as the executable and in the root of the SD card; neither worked) How are you supposed to use the function TPL_OpenTPLFromFile? Loading at compile time would be fine too, but I don't understand how the image file is converted and the header files are produced in the example.

MODIFIED:

Code: Select all

GX_InvVtxCache();
GX_InvalidateTexAll();
TPL_OpenTPLFromFile(&neheTPL, "NeHe.bmp");
TPL_GetTexture(&neheTPL,0,&texture);
// setup our camera at the origin
// looking down the -z axis with y up
guLookAt(view, &cam, &up, &look);
ORIGINAL:

Code: Select all

GX_InvVtxCache();
GX_InvalidateTexAll();
TPL_OpenTPLFromMemory(&neheTPL, (void *)NeHe_tpl,NeHe_tpl_size);
TPL_GetTexture(&neheTPL,nehe,&texture);
// setup our camera at the origin
// looking down the -z axis with y up
guLookAt(view, &cam, &up, &look);

Re: Textures directly from files

Posted: Sat Jun 26, 2010 2:57 am
by dancinninja
Maybe it doesn't know where to look? What if you put:

Code: Select all

sd:/whatever.bmp
Have you tried converting it to a different image format? Maybe it's the "bmp".

Re: Textures directly from files

Posted: Tue Jul 06, 2010 6:44 am
by Lin
You could be right about the file format. I don't know if that's what's really causing my problem, but after looking up about the .BMP file format I find that it's specified as little-endian. The Wii being big-endian (or at least running as such), that could pose a problem to reading the header data.

Re: Textures directly from files

Posted: Wed Jul 07, 2010 4:07 pm
by WinterMute
Slight clue in the function name, TPL_OpenTPLFromFile loads a tpl file - these are generated using gxtexconv.

Re: Textures directly from files

Posted: Sat Jul 24, 2010 5:38 pm
by Lin
That helped. I got it working at last. The filename definitely needed the path prefix "sd:", and I also needed to call fatMountSimple before the texture load call, as in

Code: Select all

__io_wiisd.startup();
fatMountSimple("sd", &__io_wiisd);

TPL_OpenTPLFromFile(&neheTPL, "sd:/NeHe.tpl")
WinterMute, are you some sort of benevolent deity? You manage the tools AND answer everybody's questions, probably over and over again. Thank you very much.

Re: Textures directly from files

Posted: Sat Jul 24, 2010 9:22 pm
by Izhido
Not 100% sure about the deity part... but I can assure you, he IS the author of all devkit*** toolchains. So yeah :D

Re: Textures directly from files

Posted: Sun Jul 25, 2010 10:43 am
by WinterMute
The correct code should be

Code: Select all

fatInitDefault();
TPL_OpenTPLFromFile(&neheTPL, "/NeHe.tpl");
Direct reference to the storage device should be avoided. Ideally you should also avoid explicit root paths since the launchers will set argv which leaves the working directory set to the path of the dol.

Re: Textures directly from files

Posted: Tue Apr 16, 2013 5:38 pm
by DolphinG89
I'm having a problem with this lesson aswell with a black texture but nothing seems to fix it can you show exactly how you set up the file and how to get it to show more than a black cube with dolphin through eclipse.

Re: Textures directly from files

Posted: Sun Jul 28, 2013 8:44 pm
by antidote
is the texture resolution in powers of 2?