Teen Programmers Unite  
 

 

Return to forum top

help loading Gfx in Allegro

Posted by BigArt [send private reply] at May 04, 2001, 07:42:39 PM

I am trying to write a piece of code that will load a certain graphic depending on the value of a certain variable. I am using Allegro and the DJGPP compiler. It sounds so simple, yet i am going insane trying to remember how to do this type of thing. i.e: if the variable equals 2 it will load screen2.bmp, if it equals 5 it will load screen5.bmp, and so on. for now i would like to accomplish this without the use of a datafile, and i am hoping for a solution more efficient then hundreds of if-then statements, so far i am fumbling with useles lines of code such as this:

int screen;
BITMAP *bitmap;
bitmap = load_bitmap("screens/screen";screen;".bmp", pal);

(which of course doesn't work at all)
i hope that will give you some idea of what im trying to accomplish. any ideas or help you could provide would be greatly appreciated. Thanks

-Art N

analyzz@jps.net
AIM: BigArt0959

Posted by Psion [send private reply] at May 04, 2001, 08:12:46 PM

Look up the sprintf function.

Posted by taubz [send private reply] at May 04, 2001, 08:14:55 PM

I don't know anything about Allegro... but... use sprintf?

- taubz

Posted by taubz [send private reply] at May 04, 2001, 08:15:26 PM

Doh.... serves me right for taking so long to write my reply!

- taubz

Posted by Psion [send private reply] at May 04, 2001, 08:38:46 PM

Now you're going to gaol.

Posted by taubz [send private reply] at May 05, 2001, 10:55:45 AM

gaol?

Posted by AngelOD [send private reply] at May 05, 2001, 07:42:30 PM

Yeah... The following should work fine:

int screen;
BITMAP *bitmap;
char filename[50];
sprintf(filename, "screens/screen%d.bmp\0", screen);
bitmap = load_bitmap(filename, pal);

Or, if you're using DOS...

int screen;
BITMAP *bitmap;
char filename[50];
sprintf(filename, "screens\\screen%d.bmp\0", screen);
bitmap = load_bitmap(filename, pal);


I add the '\0' at the end because some compilers doesn't add it automatically (don't believe it's required to either).

Posted by Psion [send private reply] at May 05, 2001, 08:43:28 PM

All compilers add '\0' automatically, and '/'s are always valid in file paths thanks to helpful standard libraries. Also, the point was to have him look it up and figure out how to do it himself. :P

Posted by AngelOD [send private reply] at May 06, 2001, 05:10:43 AM

Whut the? Did I write all that? That's kinda creepy... I know that the '/'s are always valid, which makes me wonder why I wrote the other... Cuz even though I was partially drunk, and exceptionally tired, I still shouldn't have been able to make that mistake...

And about the compilers always adding '\0' at the end... I once used one that didn't, which is why I now make sure to always add it manually... After all, it doesn't really matter if I put it there, so let me have my fun. :P

Oh, and sorry about spoiling your plan to make the guy find the information himself. ;)

Posted by Psion [send private reply] at May 06, 2001, 11:16:33 AM

Any compiler that does not add the terminating 0 will make hello world programs crash horribly, so no doubt you were also drunk when you made this "discovery" at the same time you "invented" a way to create cold fusion in lettuce! ;-P

Posted by AngelOD [send private reply] at May 06, 2001, 04:46:29 PM

Hey! :P
If you weren't admin I would, errm, say that you're mean. Anyhow, I'll avoid commenting in the future... No use anyway...

Posted by gian [send private reply] at May 06, 2001, 11:08:18 PM

Dammit, are you saying that you can't create cold fusion in lettuce? I'll have to think of another science fair project then...

Posted by AngelOD [send private reply] at May 07, 2001, 12:28:47 PM

Heheh... :P

You must be logged in to post messages and see which you have already read.

Log on
Username:
Password:
Save for later automatic logon

Register as a new user
 
Copyright TPU 2002. See the Credits and About TPU for more information.