delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/10/14/17:39:22

From: Chris Frolik <cfrolik AT purdue DOT edu>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Allegro mode 13h
Date: Wed, 14 Oct 1998 14:06:03 -0500
Organization: -
Lines: 67
Message-ID: <3624F61B.2A62BEC9@purdue.edu>
References: <01bdf794$4a8e4460$5e9bf482 AT s-64584>
NNTP-Posting-Host: shrv-a-033.resnet.purdue.edu
Mime-Version: 1.0
X-Mailer: Mozilla 4.06 [en] (Win98; I)
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

> [---Snip---]
> #include <allegro.h>
> 
> int main(void)
> {
>    allegro_init();
>    set_gfx_mode(GFX_VGA, 320, 200, 0, 0);
>    install_keyboard();
> 
>    BITMAP *image;
>    PALETTE *pal;

Your main problem is that `pal' is declared wrong here.  It should be:
     PALETTE pal;
PALETTE is typedef'd so that it will be an array of 256 RGB structures. 
Declaring a  (PALETTE*) will
actually declare a pointer to an array of RGB structures, which is not
what load_bitmap() asks for.

>    image = create_bitmap(16, 16);

You don't need the above line.  In fact, it will lead to memory leaks. 
You're creating a bitmap, and then loading a bitmap to that same pointer
in the next line.  load_bitmap() will create the bitmap for you.

>    image = load_bitmap("test.bmp", pal);

You should check the value returned by load_bitmap() before you attempt
to use it.  For example:

    if (!image) {
       allegro_exit();
       fprintf(stderr, "Oops!  Error loading bitmap file TEST.BMP\n");
       return 1;
    }

Also, you probably want to set the palette to the `pal' variable, which
will now hold the palette
of the image you loaded.  Just call:

set_palette(pal);

> 
>    blit(image, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);

The last two values of blit() should be the width/height of the source
bitmap, which you probably
want to be   image->w, image->h   instead of    SCREEN_W, SCREEN_H.

Note that you need to destroy the bitmap you loaded before you call
allegro_exit().  Do this with:

destroy_bitmap(image);

> 
>    readkey();
>    allegro_exit();
>    return 0;
> }
> [---End of Snip---]

> 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 *)'
> It have something to do with the palette, I want to use the colors the
> image was draw with.

- Raw text -


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