PalmTree
07-20-2004, 05:46 AM
Hi. I'm trying to write a BSP rendering module for my engine that will take existing .BSP files (as spat out by WorldCraft etc). Thing is, I've got all the geometry loaded and happening but I can't load the textures properly!
I have some code I found on the net to load a .JPG but they come out all wishy-washy with a hint of blue. The PCX files look great. I have nothing to load in a .TGA at all so I've also got some white faces in the level.
Anyone got any code to at least load a JPEG and maybe a TGA too please ?
I've seen the various open-source LibJPEG, LibTIF etc but tbh they're a bit of a nightmare. LibTIFF for example has about 96 million files! I want just one please, or at least one per format.
Anyone know where to look ?
Many thanks...
PalmTree
07-20-2004, 05:53 AM
My bad. I suddenly realised that BSP doesn't use PCX - they're left over from a conversion job I did with some freeware crap before I wrote my own JPEG loader. It's the converter that messed em up - my JPEG loader seems to work just fine. :)
So, anyone got a TGA loader that resides in a single file or *small* group of files please ?
wazoo
07-20-2004, 06:00 AM
www.gametutorials.com
There's quite a few image format loading code there, and has a tutorial on loading RLE-compressed TGA images..
<plug>I used the same code as well for a set of articles I had written a while ago now for gamedev</plug>
hth
lexaloffle
07-20-2004, 07:19 AM
From graphics gems:
http://www.acm.org/pubs/tog/GraphicsGems/gemsv/ch7-6/tga/
TGA is quite a simple format though. If you don't feel like messing around with someone else's implementation, and you don't need a robust loader, it might be worth writing your own. You can get the specification from wotsit.org (http://www.wotsit.org).
Heck, here's mine. It just reads 32-bit uncompressed images.
(disclaimer: hacky code follows)
int disk_import_bitmap_tga(char *file_name)
{
FILE *f;
uint8 id_length, palette_type, image_type, bpp, desc;
uint8 skip[256];
uint16 w, h;
int x, y;
int my;
f = fopen(file_name, "rb");
if (!f) return;
fread(&id_length, sizeof(uint8), 1, f);
fread(&palette_type, sizeof(uint8), 1, f);
fread(&image_type, sizeof(uint8), 1, f);
if (image_type != 2 || palette_type != 0)
{
fclose(f);
return 1;
}
fread(skip, 1, 5, f); //palette stuff
fread(skip, 1, 4, f); //left, top
fread(&w, sizeof(uint16), 1, f);
fread(&h, sizeof(uint16), 1, f);
fread(&bpp, sizeof(uint8), 1, f);
fread(&desc, sizeof(uint8), 1, f);
fread(skip, sizeof(uint8), id_length, f); //image id
for (y = 0; y < h; y++)
{
my = (desc & 0x20) ? y : h-y-1; //flit vertically?
//bmp_dat->line[my] is a pointer to the current row of bitmap data
fread(bmp_dat->line[my], w * bpp/8, 1, f);
}
fclose(f);
return 0;
}
PalmTree
07-20-2004, 07:38 PM
Excellent stuff all round - many thanks guys :)