TGA Font Loader - LMNOpc
Hi All
I have developed a TGA Font texture loader / builder based on NeHe's Tut24. It all works fine and dandy when I use the original font.tga as provided by the tut.
However, I wanted to use a different typeface and so I created a new 256x256 TGA font texture using LMNOpc's bitmap font builder. (www.lmnopc.com)
The only problem now is that when I replace NeHe's font.tga with my new font.tga the characters look all wrong on the screen. It's as though the texture has not been mapped correctly to the QUAD and yet if I load both TGAs into PaintshopPro they look OK. - Same orientation, same char positions, everything !
By the way, if I use NeHe's Lesson24 code and replace the font.tga in the data subdir with my new font.tga I get the same gobbledygook results, and that's without even touching or re-building the Lesson24.exe bin that comes with the download.
This proves it must be the LMNOpc TGA file and yet they look visually the same!
Has anyone else had this problem ?
Joe
UK
[edited by - JoeDeuter on August 30, 2003 8:45:41 AM]
Nah, it''s definitely not compressed because NeHe''s Tut 24 only loads in uncompressed TGAs. (IE: It looks for the first 12 header bytes to be {0,0,2,0,0,0,0,0,0,0,0,0})
I actually see characters OK, they just seem to be the wrong ones and upside down. It''s as though the origin is all messed up.
The thing is, the TGAs look OK when loaded into PaintshopPro. (IE, correct orientation, etc)
Anyone else used LMNOpc font builder. Anyone have any ideas ?
Joe
I actually see characters OK, they just seem to be the wrong ones and upside down. It''s as though the origin is all messed up.
The thing is, the TGAs look OK when loaded into PaintshopPro. (IE, correct orientation, etc)
Anyone else used LMNOpc font builder. Anyone have any ideas ?
Joe
August 31, 2003 01:43 AM
afaik tga has a variable in the header that tells if origin is IN TOP-LEFT OR BOTTOM-LEFT CORNER.. (damn caps-lock!) Does your/nehes tga loader check that?
- Is your font the same size as NeHe's? (ie. 128x128, etc)
- What character set did you save yours as was it 256 ASCII or the double NeHe style font ("Character set" in LMNOpc at top)
- Maybe the fonts are different sizes?
- Did you save it flipped diagonally?
- Did you use char smoothing in LMNOpc?
try these, or maybe the alpha channel is being used incorrectly in your paint program
[edited by - NumberXaero on August 31, 2003 3:18:23 AM]
- What character set did you save yours as was it 256 ASCII or the double NeHe style font ("Character set" in LMNOpc at top)
- Maybe the fonts are different sizes?
- Did you save it flipped diagonally?
- Did you use char smoothing in LMNOpc?
try these, or maybe the alpha channel is being used incorrectly in your paint program
[edited by - NumberXaero on August 31, 2003 3:18:23 AM]
A lot of the time images are stored bottom-first. TGAs default to bottom-first. The TGA files specify which order they were saved in, other formats might not have an option.
[edited by - Nypyren on August 31, 2003 4:04:25 AM]
[edited by - Nypyren on August 31, 2003 4:04:25 AM]
I found that NeHe''s TGA loading code doesn''t work correctly all the time. I think there are several formats of TGA''s available (besides compressed/uncompressed). I searched the web for a TGA loading function and found one that loads all of the TGA''s I''ve used. (I''m pulling this code from my ''old source'' database, so I''m hoping it''ll still work)
Oh, and on a side note, if you''re using Photoshop 7, Adobe messed up their TGA plugin - it creates nonstandard TGAs. Either download the fixed plugin or install the update.
#define TGA_RLE 10typedef struct{ UCHAR* data; // raw image data UINT bits; // bitdepth WORD width; WORD height; UINT channels; // 3 or 4 UINT id; // open GL bind id} TGAimage_t;LoadTGA(LPCSTR path, TGAimage_t *pImgData){ FILE *pFile = NULL; byte length = 0; byte imgType = 0; int stride = 0; int i = 0; if((pFile = fopen(path, "rb")) == NULL) return false; fread(&length, sizeof(byte), 1, pFile); fseek(pFile,1,SEEK_CUR); fread(&imgType, sizeof(byte), 1, pFile); fseek(pFile, 9, SEEK_CUR); fread(&pImgData->width, sizeof(WORD), 1, pFile); fread(&pImgData->height, sizeof(WORD), 1, pFile); fread(&pImgData->bits, sizeof(byte), 1, pFile); fseek(pFile, length + 1, SEEK_CUR); // If not a RLE encoded image... if(imgType != TGA_RLE) { // Check for 24 or 32 Bit if(pImgData->bits == 24 || pImgData->bits == 32) { pImgData->channels = pImgData->bits / 8; stride = pImgData->channels * pImgData->width; pImgData->data = new UCHAR[stride * pImgData->height]; for(int y = 0; y < pImgData->height; y++) { UCHAR *pLine = &(pImgData->data[stride * y]); fread(pLine, stride, 1, pFile); for(i = 0; i < stride; i += pImgData->channels) { int temp = pLine[i]; pLine[i] = pLine[i + 2]; pLine[i + 2] = temp; } } } // Check for 16 Bit else if(pImgData->bits == 16) { USHORT pixels = 0; int r=0, g=0, b=0; pImgData->channels = 3; stride = pImgData->channels * pImgData->width; pImgData->data = new UCHAR[stride * pImgData->height]; for(int i = 0; i < pImgData->width*pImgData->height; i++) { fread(&pixels, sizeof(USHORT), 1, pFile); b = (pixels & 0x1f) << 3; g = ((pixels >> 5) & 0x1f) << 3; r = ((pixels >> 10) & 0x1f) << 3; pImgData->data[i * 3 + 0] = r; pImgData->data[i * 3 + 1] = g; pImgData->data[i * 3 + 2] = b; } } else return false; } // If the image is RLE encoded else { byte rleID = 0; int colorsRead = 0; pImgData->channels = pImgData->bits / 8; stride = pImgData->channels * pImgData->width; pImgData->data = new UCHAR[stride * pImgData->height]; byte *pColors = new byte [pImgData->channels]; while(i < pImgData->width*pImgData->height) { fread(&rleID, sizeof(byte), 1, pFile); if(rleID < 128) { rleID++; while(rleID) { fread(pColors, sizeof(byte) * pImgData->channels, 1, pFile); pImgData->data[colorsRead + 0] = pColors[2]; pImgData->data[colorsRead + 1] = pColors[1]; pImgData->data[colorsRead + 2] = pColors[0]; if(pImgData->bits == 32) pImgData->data[colorsRead + 3] = pColors[3]; i++; rleID--; colorsRead += pImgData->channels; } } else { rleID -= 127; fread(pColors, sizeof(byte) * pImgData->channels, 1, pFile); while(rleID) { pImgData->data[colorsRead + 0] = pColors[2]; pImgData->data[colorsRead + 1] = pColors[1]; pImgData->data[colorsRead + 2] = pColors[0]; if(pImgData->bits == 32) pImgData->data[colorsRead + 3] = pColors[3]; i++; rleID--; colorsRead += pImgData->channels; } } } } fclose(pFile); return true;}
Oh, and on a side note, if you''re using Photoshop 7, Adobe messed up their TGA plugin - it creates nonstandard TGAs. Either download the fixed plugin or install the update.
Thanks for all that.
Although I suspect that the origin was messed up somehow, I got around the problem by saving the LMNOpc font as a *.bmp bitmap. I then converted this to a TGA using PaintShop Pro, which I know saves the files correctly cause I use it all the time to touch up my other textures. It works a charm now.
I even got a little more adventurous by adding a routine that loads in the FontMetrics.dat file and translates each character proportionally based on its width. Voila – I now have a neat looking proportionally spaced Arial Font on my screen.
Although I suspect that the origin was messed up somehow, I got around the problem by saving the LMNOpc font as a *.bmp bitmap. I then converted this to a TGA using PaintShop Pro, which I know saves the files correctly cause I use it all the time to touch up my other textures. It works a charm now.
I even got a little more adventurous by adding a routine that loads in the FontMetrics.dat file and translates each character proportionally based on its width. Voila – I now have a neat looking proportionally spaced Arial Font on my screen.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement