Mail Archives: djgpp/1998/10/14/14:02:30
On Wed, 14 Oct 1998, Tarad wrote:
> Hya, I'm kinda new in graphic programming in C/C++ so I deceided to use
> allegro for my very first game with real graphic (well mode 13h anyway). I
> made this test program to see if I could blit a bitmap to the screen and it
> didn't work. Why?
If you have a WIP, please read the file `help.txt'. If not, you
can read it here:
http://www.talula.demon.co.uk/allegro/help.html
It gives suggestions on debugging this sort of thing, and how to
ask questions here and in particular on the Allegro mailing
lists.
> [---Snip---]
> #include <allegro.h>
>
> int main(void)
> {
> allegro_init();
> set_gfx_mode(GFX_VGA, 320, 200, 0, 0);
You should check the return value of `set_gfx_mode'; if it's
less than 0, the mode could not be set. It's always worth
doing, even if you're fairly sure the mode can't fail to be set.
> install_keyboard();
>
> BITMAP *image;
I assume you're using C++; in C variables must be declared at
the top of a block.
> PALETTE *pal;
^
This is why your code doesn't compile; remove the *.
> image = create_bitmap(16, 16);
This is redundant (and a memory leak) because you're loading a
bitmap anyway. You don't need to do any creating. In addition,
if you did need to create, you should check that you were given
a valid pointer back and not NULL. If you get NULL, you're out
of memory.
> image = load_bitmap("test.bmp", pal);
Again, check that the returned pointer is not NULL. It's
especially important here; if the file could not be loaded then
NULL will be returned and you should complain to the user.
> compiling with the allegro library I got this error:
> game.cc: In function `int main()':
> game.cc:12: passing `RGB (*)[256]' as argument 2 of `load_bitmap(char *,
> RGB *)'
As I wrote above, your declaration of `pal' was wrong.
`PALETTE' is an array of RGB; you can pass it directly to this
sort of function (it will be passed as a pointer to the first
element, which is of type `RGB *', which is what `load_bitmap'
expects to receive).
--
george DOT foot AT merton DOT oxford DOT ac DOT uk
xu do tavla fo la lojban -- http://xiron.pc.helsinki.fi/lojban/lojban.html
- Raw text -