Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Improper masking

This thread is locked; no one can reply to it. rss feed Print
Improper masking
horizon981
Member #7,594
August 2006

I was learing how to draw masked sprites, the mask color of course, being pink.
Here's my code

1#include <allegro.h>
2 
3int 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}
21END_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.

Kitty Cat
Member #2,815
October 2002
avatar

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.

--
"Do not meddle in the affairs of cats, for they are subtle and will pee on your computer." -- Bruce Graham

Kauhiz
Member #4,798
July 2004

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.

---
It's Ridge Racer! RIIIIIDGE RAAAAACER!

horizon981
Member #7,594
August 2006

Thanks. But if the semi colon at

is an error, why do the programs compile at all?

Kauhiz
Member #4,798
July 2004

---
It's Ridge Racer! RIIIIIDGE RAAAAACER!

Kitty Cat
Member #2,815
October 2002
avatar

Quote:

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.

--
"Do not meddle in the affairs of cats, for they are subtle and will pee on your computer." -- Bruce Graham

Go to: