pouët.net

Go to bottom

coding Q - allegro - FAIL struct with array of BITMAP

category: general [glöplog]
 
I'm working on some code for a game, here is a snippet.

Code: struct animImage{ string animName; //name of animation int frames; //num of frames BITMAP * frame[999]; //array to hold frames int loaded; int origXres; //original res of frame (will be scaled) int origYres; //" " }; int main(){ animImage win1; win1.animName = ("win1"); win1.frames = 6; win1.loaded = 0; win1.origXres = 800; win1.origYres = 600; win1 = load_anim(win1); } //loop adds each frame of animation to an array of bitmaps animImage load_anim(animImage anim){ string path = ("data\\anim\\"); string ext = (".tga"); string fullstring = ""; for(int i = 0; i < anim.frames; i++){ //int to string code string s; stringstream out; out << i; s = out.str(); fullstring = path + anim.animName + s + ext; anim.frame[i] = load_tga(fullstring.c_str(),false); } anim.loaded = 1; return anim; }


It builds fine. I did some bread crumb debugging and found that the line it crashes on is...

anim.frame[i] = load_tga(fullstring.c_str(),false);

I did some searching and found someone working with arrays of bitmaps, and they mentioned to set each frame to 0 before starting. I tried this with something like this...

for(int i = 0; i < anim.frames; i++){
anim.frame[i] = 0;
}

Still no luck. :(
Any help would be most appreciated! =]
added on the 2008-11-09 15:02:02 by b0ib0t b0ib0t
According to the documentation:
BITMAP *load_tga(const char *filename, RGB *pal);

why is your RGB pointer set to false?
added on the 2008-11-09 15:33:45 by trc_wm trc_wm
That is funny, I never just tore through the Allegro manual and found nothing that says its ok to give "false" as an arg to load_tga. Its funny because for some reason it works. LOL

As for the problem, I solved it. My code is all in 1 file and its near 2000 lines. I haven't had my morning cup of coffee so I wasn't paying good attention, and put the load_anim() before my sysInit(). The code was crashing because I hadn't initialized Allegro before calling load_tga() inside of my function. DOH!

One question leads to another, now I must know why passing false works...
added on the 2008-11-09 15:45:27 by b0ib0t b0ib0t
I assume it works because false == NULL and it seems that allegro just ignores the second parameter if it's a NULL pointer.
added on the 2008-11-09 16:13:56 by masterm masterm
Missed this part in the manual.

Code: The pal argument may be NULL. In this case, the palette data are simply not returned. Additionally, if the file is a truecolor image and the destination color depth is 8-bit, the color conversion process will use the current palette instead of generating an optimized one.
added on the 2008-11-09 16:15:31 by b0ib0t b0ib0t
so "b0ib0t", what did we learn today?

ahyes, rtfm!
added on the 2008-11-09 22:01:51 by skrebbel skrebbel
I did read it, but I had missed over part. What I learned today was rtfm2x ;)
added on the 2008-11-09 22:03:43 by b0ib0t b0ib0t
and coffee :)
added on the 2008-11-09 22:05:51 by skrebbel skrebbel
Weird!! I did find the answer after having a cup of coffee. I think the lesson to be learned here is, do not code before having coffee!
added on the 2008-11-10 00:17:25 by b0ib0t b0ib0t
Shouldn't
string path = ("data\anim\");
be
string path = ("data\\anim\\");

Just an idea...

added on the 2008-11-10 08:07:45 by Jcl Jcl

login

Go to top