create_bitmap(3alleg4)

πŸ’– create_bitmap πŸ’–

okay bestie, so this is a page from the Allegro manual β€” yes, the Allegro game programming library, we're being ✨productive✨ today β€” and it's all about the function create_bitmap. Let's get into it, i promise it's not scary 🫢


✨ NAME ✨

create_bitmap β€” makes you a memory bitmap 🎨 Allegro game programming library energy, periodt.


🌸 SYNOPSIS 🌸

#include <allegro.h>

BITMAP *create_bitmap(int width, int height);

πŸŽ€ DESCRIPTION πŸŽ€

So basically, create_bitmap creates a memory bitmap that's width by height. That's it. That's the vibe. πŸ’…

Here's the tea tho, and you're gonna wanna hear this:

  • The bitmap comes with clipping turned on, and the clipping rectangle is set to the full size of the bitmap. So it's ready to go, no extra setup.
  • the image memory will NOT be cleared. not me finding out the hard way 😭 it will probably contain garbage, so like... bestie, please clear the bitmap before you use it. fr fr. don't skip this step.
  • this routine always uses the global pixel format, as specified by calling set_color_depth().
  • the minimum height of the BITMAP must be 1, and width can't be negative. that's the rule, no cap 🚫

Here's the example, verbatim, because i would never mess with your code:

/* Create a 10 pixel tall bitmap, as wide as the screen. */
BITMAP *bmp = create_bitmap(SCREEN_W, 10);
if (!bmp)
   abort_on_error("Couldn't create bitmap!");
/* Use the bitmap. */
...
/* Destroy it when we don't need it any more. */
destroy_bitmap(bmp);

look at that. iconic. the SCREEN_W for width and 10 for height, the null check with abort_on_error, and then destroy_bitmap when you're done. main character energy honestly πŸ‘‘


🌈 RETURN VALUE 🌈

It returns a pointer to the created bitmap, or NULL if the bitmap could not be created. so like, always check for NULL, bestie, don't just rawdog it πŸ™ˆ

and remember to free this bitmap later to avoid memory leaks! your future self will thank you. lowkey highkey the most important sentence on this page. πŸ“


πŸ¦‹ SEE ALSO πŸ¦‹


and that's the whole page, bestie!! πŸ’– this was Allegro version 4.4.3, and the page itself is create_bitmap(3alleg4) β€” go forth and allocate responsibly, mwah πŸŽ€βœ¨πŸ§š