delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/10/14/14:02:30

Date: Wed, 14 Oct 1998 19:00:57 +0100 (BST)
From: George Foot <george DOT foot AT merton DOT oxford DOT ac DOT uk>
To: djgpp AT delorie DOT com
Subject: Re: Allegro mode 13h
In-Reply-To: <01bdf794$4a8e4460$5e9bf482@s-64584>
Message-ID: <Pine.OSF.4.05.9810141854430.23285-100000@sable.ox.ac.uk>
MIME-Version: 1.0
Reply-To: djgpp AT delorie DOT com

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019