 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
ayatollah
Joined: 04 Sep 2005 Posts: 15
|
Posted: Sat Jan 28, 2006 8:37 pm Post subject: Anyone using PSPTexTool for Textures? |
|
|
I was wondering if anybody out there is using PSPTexTool 0.00001 by Henrik Rydgård to convert textures?
I am not really good in IO stuff and have troubles loading the textures and applying them.. The DOC in the ZIP describes an own format and not GU which is not that hard but it says in his textureheader struct:
| Code: | typedef struct
{
u32 ID; // == 'PSPT'
u16 bufWidth; //(NOTE! if bufwidth < xsize then so be it! Obey bufwidth always!)
u16 bufHeight; //(OBEY bufHeight too, with these we can achieve nonpow2 textures if we set texcoords appropriately)
u16 flags; //{1=Swizzle}
u8 xsize; //(1<<xsize = texture size in pixels)
u8 ysize;
u8 format;
u8 numMips;
u8 numCluts;
u8 clutSize; // or reserved
//OK we here have 16 bytes. Everything (textures, palettes) needs to be 16-byte aligned
//Here comes a variable number of pointers to fix up
//Then comes the texture data for each level
//All of the texture data are 16-byte aligned
} TextureHeader;
|
Right at the end
Here comes a variable Number of pointers to fix up
then comes the texture data for each level..
What I successfully can do until now is to load the Texture HEADER (16 bytes) and display this...
But how do I move on and load the actual palette and texture data??
My Load Routine is:
| Code: | void *loadTexture(char *filename, TextureHeader *hdr, *texture)
{
SceUID myFile;
myFile = sceIoOpen(filename, PSP_O_RDONLY, 0777);
if(!myFile)
{
pspDebugScreenPrintf("Error loading file %s", filename);
return NULL;
}
sceIoLseek(myFile, 0x00, SEEK_SET);
sceIoRead(myFile, hdr, sizeof(TextureHeader));
sceIoClose(myFile);
return (void *)0xDEADBEEF; // ignore
} |
Maybe somebody has a snip of their own code that shows how I proceed after loading the HEADER?
Your help is greatly appreciated! |
|
| Back to top |
|
 |
Raphael

Joined: 17 Jan 2006 Posts: 646 Location: Germany
|
Posted: Sun Jan 29, 2006 12:43 am Post subject: |
|
|
Well, if you take a look at the code, you see that this guy, after the header, places a list of offsets to the mipmaps and cluts. So just do this (in pseudo code):
for (i=0;i<numMips+numClut;i++)
seek(file, 16+i*4, SEEK_SET);
read(file, &offset[i], 4);
now you can just read the mipmap N by doing this:
seek(file, offset[N], SEEK_SET);
read(file, &tex, (bufwidth >> N)*(bufheight >> N)*bpp );
where bpp is the bytes per pixel with the given tformat (lower 4bit of formats). with RGBA1555 it would be 2 for example.
Now if you have a CLUT texture format, you'd also have to read the appropriate CLUT, which is done by doing this:
seek(file, offset[numMips+N], SEEK_SET);
read(file, &clut, clutSize*entrySize);
where clutSize is either 16 for CLUT4 or 256 for CLUT8 and entrySize is the bytes per pixel with given palformat (upper 4 bit of formats). See above for example.
Then you have the data you need to process to the GU directly in tex and clut, you'd just have to provide if swizzling was applied when uploading texture and clut. Don't forget that tex and clut have to be alligned to 16byte though.
Hope this helps. |
|
| Back to top |
|
 |
ayatollah
Joined: 04 Sep 2005 Posts: 15
|
Posted: Sun Jan 29, 2006 4:25 am Post subject: |
|
|
Ok.. I know where you are coming from... however I still have a problem here .. I am sure it's because of my weak general C Knowledge but I will give it another try to get help :)
I tried reading the values from the Textures myself and simply read it (without using variables since I get confused with the pointers and want to get it to load like you wrote once I know it's really working!)
I have this:
| Code: |
sceIoLseek(myFile, 0x00, SEEK_SET);
sceIoRead(myFile, hdr, sizeof(TextureHeader));
|
This loads the first 16 Bytes (my texture Header is still like this:
| Code: |
typedef struct
{
u32 ID; // == 'PSPT'
u16 bufWidth; //(NOTE! if bufwidth < xsize then so be it! Obey bufwidth always!)
u16 bufHeight; //(OBEY bufHeight too, with these we can achieve nonpow2 textures if we set texcoords appropriately)
u16 flags; //{1=Swizzle}
u8 xsize; //(1<<xsize = texture size in pixels)
u8 ysize;
u8 format;
u8 numMips;
u8 numCluts;
u8 clutSize; // or reserved
//OK we here have 16 bytes. Everything (textures, palettes) needs to be 16-byte aligned
//Here comes a variable number of pointers to fix up
//Then comes the texture data for each level
//All of the texture data are 16-byte aligned
} TextureHeader;
|
since the offset to the MipMaps and CLUTs (I am using a CLUT8 Texture with 8888 Palette (since the converter does only this!) should be included in the struct, how can i specify them?? they are 32bit but according to the number of MIPMAPS they have either 4 or 1 set of 32bit chunks.. same for the CLUTs..
I tried to save the texture without MIP MAPs and the file
shows:
0x00 - 0x0f => Texture Header
0x10 - 0x13 => Offset to Texture (in this case 0x20 0x00 0x00 0x00)
0x14 - 0x17 => Offset to Palette (in this case 0x20 0x00 0x01 0x00)
I am declaring the following for Texture Data and Palette at the beginning of my main.c:
| Code: |
unsigned char __attribute__((aligned(16))) dragontex[256*256];
unsigned int __attribute__((aligned(16))) dragonpal[256];
|
So without reading the Offsets from the File, I simply try to load like this:
| Code: |
/* Load actual Texture */
sceIoLseek(myFile, 0x20, SEEK_SET);
sceIoRead(myFile, &dragontex, (hdr->bufWidth)*(hdr->bufHeight));
/* Load actual first CLUT */
sceIoLseek(myFile, 0x00010020, SEEK_SET);
sceIoRead(myFile, &dragonpal, 256*4);
|
The Texture is 256x256 Pixel and since it's a CLUT8, 0x10000 is the length of it.. on the CLUT itself I am reading 256*4 since each color needs 4 Bytes..
I get some result on my cube that reflects the colors but the texture itself is completely messed up.
If i try to load the texture as raw and link it with bin2o in the Makefile it works just fine.. I just want to be more flexible and actually use that cool Converter for further projects..
I know this is completly n00b question but I still hope somebody out there can help me with this!! |
|
| Back to top |
|
 |
Raphael

Joined: 17 Jan 2006 Posts: 646 Location: Germany
|
Posted: Sun Jan 29, 2006 8:55 am Post subject: |
|
|
| Just had a short look over what you wrote, and one thing I notice is, that you declare unsigned int __attribute__((aligned(16))) dragonpal[256]; for your CLUT, but since its a CLUT8 it has 32bit and thus should be unsigned long. |
|
| Back to top |
|
 |
ayatollah
Joined: 04 Sep 2005 Posts: 15
|
Posted: Sun Jan 29, 2006 9:13 am Post subject: |
|
|
| The strangest thing is, that the load routine works fine with RAW files.. The same texure when loaded and byteflipped from RGB to ABGR works like a charm! ? ! |
|
| Back to top |
|
 |
ayatollah
Joined: 04 Sep 2005 Posts: 15
|
Posted: Sun Jan 29, 2006 9:31 am Post subject: |
|
|
| Thanx for that hints.. I finally managed to do it.. |
|
| Back to top |
|
 |
Insert_witty_name
Joined: 10 May 2006 Posts: 376
|
Posted: Fri Jul 14, 2006 10:34 pm Post subject: |
|
|
| Sorry to bump such an old topic, but I'd like any info there is on loading the textures from this tool. Thanks. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|