ok I've got a simple piece of code that shows a similar problem.
Its got something to do with the depth of functions(i think).
Maybe I'm just passing arguments wrongly, well have a look at it for me.
1 | #include <allegro.h> |
2 | #include <iostream> |
3 | |
4 | void load_image_depth_one(BITMAP*); |
5 | void load_image_depth_two(BITMAP*); |
6 | |
7 | int main(int argv,char* argc[]) |
8 | { |
9 | allegro_init(); |
10 | char address[256]; |
11 | install_timer(); |
12 | |
13 | BITMAP* background=NULL; |
14 | BITMAP* buffer[2]; |
15 | |
16 | set_color_depth(16); |
17 | set_gfx_mode(GFX_AUTODETECT_WINDOWED,800,600,0,0); |
18 | |
19 | // background=load_bmp("background.bmp",NULL); |
20 | sprintf(address,"init value of bitmap is %d",background); |
21 | allegro_message(address); |
22 | load_image_depth_one(background); |
23 | sprintf(address,"value after all layers is %d",background); |
24 | allegro_message(address); |
25 | |
26 | buffer[0]=create_video_bitmap(800,600); |
27 | buffer[1]=create_video_bitmap(800,600); |
28 | int which=0; |
29 | |
30 | while(TRUE) |
31 | { |
32 | blit(background,buffer[which], |
33 | 0,0,0,0,800,600);//draw demon background. |
34 | show_video_bitmap(buffer[which]); |
35 | which= 1 - which; |
36 | } |
37 | |
38 | } |
39 | |
40 | void load_image_depth_one(BITMAP* depth_test) |
41 | { |
42 | char address[256]; |
43 | load_image_depth_two(depth_test); |
44 | sprintf(address,"depth test in one %d",depth_test); |
45 | allegro_message(address); |
46 | |
47 | } |
48 | void load_image_depth_two(BITMAP* depth_test) |
49 | { |
50 | depth_test=load_bmp("background.bmp",NULL); |
51 | char address[256]; |
52 | sprintf(address,"depth test in two %d",depth_test); |
53 | allegro_message(address); |
54 | |
55 | } |
56 | |
57 | |
58 | END_OF_MAIN(); |
I've included the source and image in the attachment.
Why is this an Allegro Development thread? Did you mean Programming Questions?
When you pass the background pointer to the load_image_depth_one function, you pass a copy of it. When that function changes it, main never knows what the new address is. You need to have the function return the new BITMAP* (BITMAP* load_image_depth_one()), or accept a pointer to a BITMAP*:
void load_image_depth_one(BITMAP** bitmap) { *bitmap = load_bitmap("etc", NULL); }
Called using:load_image_depth_one(&background);
Please refrain from posting your programming questions to this section of the forum in the future.
When you pass the background pointer to the load_image_depth_one function, you pass a copy of it.
Oh of course, what was I thinking? No wonder it doesn't work right.
I'm sorry for posting in the wrong forum, I'll post in the right one next time.
I fix that code and it worked correctly.