I was learing how to draw masked sprites, the mask color of course, being pink.
Here's my code
1 | #include <allegro.h> |
2 | |
3 | int main() |
4 | { |
5 | allegro_init(); |
6 | set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0); |
7 | set_color_depth(24); |
8 | |
9 | install_keyboard(); |
10 | BITMAP* sprite = load_bitmap("sprite.bmp", NULL); |
11 | |
12 | clear_bitmap(screen); |
13 | //draw_sprite(screen , sprite, 0, 0); |
14 | masked_blit(sprite, screen, 0, 0, 0, 0, sprite->w, sprite->h); |
15 | readkey(); |
16 | |
17 | destroy_bitmap(sprite); |
18 | allegro_exit(); |
19 | return 0; |
20 | } |
21 | END_OF_MAIN(); |
Here's the image:
http://horizon981.googlepages.com/sprite.gif
And here's the output:
http://horizon981.googlepages.com/output.gif
What's gone wrong?
Please help me.
set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0); set_color_depth(24);
That's backwards. You need to set a color depth before setting a graphics mode. Also, 24-bit is not a good color to use. Generally you should use the desktop color depth
desktop_color_depth()
32- or 16-bit. 8-bit shouldn't be used unless your game is specificly designed for it.
This has nothing to do with your problem, but I just like to point out to everyone who makes the mistake, that END_OF_MAIN(); is wrong. It should be just END_OF_MAIN() without the ; at the end.
But if the semi colon at END_OF_MAIN(); is an error, why do the programs compile at all?
Because compilers are very lenient about it. But it's still improper code.