BITMAP(3alleg4)

πŸ’– BITMAP πŸ’–

okay bestie, welcome to the Allegro manual (3alleg4), and today's main character is BITMAP β€” the little struct that literally stores the contents of a bitmap in the Allegro game programming library. no cap. let's get into it ✨


🌸 SYNOPSIS 🌸

#include <allegro.h>

typedef struct BITMAP

πŸ¦‹ DESCRIPTION πŸ¦‹

so the struct looks like this, and yes we're reading it top to bottom like a group chat:

   int w, h;               - size of the bitmap in pixels
   int clip;               - non-zero if clipping is turned on
   int cl, cr, ct, cb;     - clip rectangle left, right, top,
                             and bottom
   unsigned char *line[];  - pointers to the start of each line

okay so, breaking it down:

  • int w, h; β€” the size of the bitmap, in pixels πŸŽ€
  • int clip; β€” non-zero if clipping is turned on
  • int cl, cr, ct, cb; β€” the clip rectangle: left, right, top, and bottom
  • unsigned char *line[]; β€” pointers to the start of each line

there is some other stuff in the structure as well, but it is liable to change and you shouldn't use anything except the above. periodt. do not touch the mystery fields. πŸ’€

the w and h fields can be used to obtain the size of an existing bitmap, like so:

   bmp = load_bitmap("file.bmp", pal);
   allegro_message("Bitmap size: (%dx%d)\n", bmp->w, bmp->h);

now the clipping rectangle lore, because this is where people get got: it is inclusive on the left and top (0 allows drawing to position 0) but exclusive on the right and bottom (10 allows drawing to position 9, but not to 10). note this is not the same format as that of the clipping API, which takes inclusive coordinates for all four corners. so like… don't mix them up, bestie πŸ™ˆ

all the values of this structure should be regarded as read-only, with the one exception of the line field, whose access is described in depth in the "Direct access to video memory" section of the manual. if you want to modify the clipping region, please refrain from changing this structure. use set_clip_rect() instead. slay responsibly πŸ’…

✨ SEE ALSO ✨


and that's the whole page, gorgeous 🫢 this was Allegro, version 4.4.3, serving you BITMAP(3alleg4) realness. go forth and never write to a struct field you weren't supposed to. mwah πŸ’‹