Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

no one

texture system problem...

This topic is 5412 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hiya Ive made a few texture loaders, such as a jpg,tga bmp and a custum format, but now I want to wrap them up in a single texture class. I had a good texture class before that handles texture management,but it only worked with bmps. I need to make a good extendable class which handles multiple format management. Also, say you have 3 models, each one takes either a bmp jpg or tga, how can you switch to the correct loader depending on the file name? Do you guys have any pointers for me as to making a good texture system? Thanks. [edited by - no one on November 27, 2003 1:25:37 AM]

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
you have a couple of methods: the most rebust way would be to read the header in from the file and determine the format that way or the easiest way is to compare the filename''s extension to a known one:
if (strcmp(".tif", filename + strlen(filename) - 4) == 0)
{
cout << "Tif file found" << endl;
}

enjoy

Mr C

Share this post


Link to post
Share on other sites
Yup, just check the last 3 letters of the string of the texture HD location and then see to what file extension of your texture manager it is equal to.

Share this post


Link to post
Share on other sites
Personally I prefer keeping the file headers as vars, and comparing with those, then reading in the first few bytes and comparing
eg

static const char BMPHeader[2] = {''B'',''M''};
static const char TGAHeader[10]....
//.......
if( memcmp( headerIJustRead, BMPHeader, 2 ) == 0 )
// Its a bmp!
else if ....

Share this post


Link to post
Share on other sites
You may wish to consider putting it in a dll so you can easily add support for other file types.

Share this post


Link to post
Share on other sites
the way i do it is that i add the extention to the filename for each format i can load and check if it exists, then i select the best format(acording to a ranking list) and load that format trough a separate function.

This is the code i use, minus the individual texture loading functions


int exist(char filename[25])
{
FILE *file;
file = fopen(filename,"rt");

if (file == NULL) {return 0;}

else {fclose(file); return 1; }
}



unsigned int LoadGLTextures(char filename[25],int filter)
{
unsigned int texture;
int format;
/*
0 : bmp
1 : tga
2 : jpg
3 : png
*/

char namebmp[60],nametga[60],namejpg[60],namepng[60];

strcpy(namebmp,filename);
strcat(namebmp,".bmp");
if (exist(namebmp)) format=0;

strcpy(nametga,filename);
strcat(nametga,".tga");
if (exist(nametga)) format=1;

strcpy(namejpg,filename);
strcat(namejpg,".jpg");
if (exist(namejpg)) format=2;

strcpy(namepng,filename);
strcat(namepng,".png");
if (exist(namepng)) format=3;


switch (format)
{
case 0:
texture=Loadbmp(namebmp,filter);
break;
case 1:
texture=Loadtga(nametga,filter);
break;
case 2:
//texture=Loadjpg(namejpg,filter);

break;
case 3:
//texture=Loadpng(namepng,filter);

break;

default:
texture=Loadbmp(namebmp,filter);
break;

}


return texture; // Return The Status

}


[edited by - lc_overlord on November 29, 2003 8:36:50 AM]

Share this post


Link to post
Share on other sites
Look at this thread to get some more ideas.
http://www.gamedev.net/community/forums/topic.asp?topic_id=193107



You should never let your fears become the boundaries of your dreams.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!