Re: [Plib-devel] JPEG loader
Brought to you by:
sjbaker
From: Trent G. <tm...@cy...> - 2000-05-31 07:15:23
|
* Steve Baker <sjb...@ai...> wrote: > I refer you to my document: "JPEGS are evil too": > > http://web2.airmail.net/sjbaker1/jpegs_are_evil_too.html They look good in my game, but I don't have much experience with this stuff so I'll take your word for it. The bad thing about it is, that all the free texture sites on the net (and most texture cd's) have only jpeg textures. Obviously converting them doesn't help with quality, and it makes them about 5-10 times the size. So until I get myself a team of artists to create original high quality textures, I have to stick with what I can find on the net for my games. When I need cartoony textures or text I'll use a lossless format. > What is really needed is to implement some kind of a plugin > arrangement for image loaders in PLIB. How about something like this? #define MAX_USER_TEXTURE_FORMATS 20 struct { char *ext; void (*loader)(char *fname, GLubyte **image, int *x, int *y, int *bpp); } user_texture_formats[MAX_USER_TEXTURE_FORMATS]; int num_user_texture_formats = 0; int add_texture_loader(char *ext, void (*loader)(char *fname, GLubyte **image, int *x, int *y, int *bpp) { if (num_user_texture_formats >= MAX_USER_TEXTURE_FORMATS) return -1; user_texture_formats[num_user_texture_formats].ext = new char [strlen(ext)+1]; strcpy(user_texture_formats[num_user_texture_formats], ext); user_texture_formats[num_user_texture_formats].loader = loader; num_user_texture_formats++; return 0; } void ssgImageLoader::loadTexture ( char *fname ) { char *p = & fname [ strlen ( fname ) ] ; while ( p != fname && *p != '.' && *p != '/' && *p != '\\' ) p-- ; if ( *p == '.' ) { if ( _ssgStrEqual ( p, ".bmp" ) ) { loadTextureBMP ( fname ) ; return ; } if ( _ssgStrEqual ( p, ".png" ) ) { loadTexturePNG ( fname ) ; return ; } if ( _ssgStrEqual ( p, ".rgb" ) || _ssgStrEqual ( p, ".rgba" ) || _ssgStrEqual ( p, ".int" ) || _ssgStrEqual ( p, ".inta" ) || _ssgStrEqual ( p, ".bw" ) ) { loadTextureSGI ( fname ) ; return ; } if ( _ssgStrEqual ( p, ".jpg" ) || _ssgStrEqual ( p, ".jpeg" ) ) { loadTextureJPEG ( fname ) ; return ; } for (int i = 0; i < MAX_USER_TEXTURE_FORMATS; i++) if ( _ssgStrEqual ( p, user_texture_formats[i].ext ) ) { GLubyte *image; int x, y, z; (*user_texture_formats[i].loader)(fname, &image, &x, &y, &z); if (image) make_mip_maps(image, x, y, z); else loadDummyTexture(); return; } } ulSetError ( UL_WARNING, "ssgImageLoader: '%s' - unrecognised file extension.", fname ) ; loadDummyTexture () ; } There's probably some errors but you get the idea. It's a lot simpler and more portable than using shared object files or DLLs. |