drawing_mode(3alleg4)

🎨 drawing_mode β€” the Allegro manual, but make it cute

okay bestie, pull up a chair, because this is the one that controls how every single pixel you draw actually lands on your bitmap. it's drawing_mode(3alleg4) from the Allegro manual, and she's lowkey iconic πŸ’…


✨ NAME ✨

drawing_mode β€” sets the graphics drawing mode. Allegro game programming library. that's it, that's the vibe πŸ¦‹


🌸 SYNOPSIS 🌸

#include <allegro.h>

void drawing_mode(int mode, BITMAP *pattern, int x_anchor, int
y_anchor);

πŸ’– DESCRIPTION πŸ’–

so. drawing_mode sets the graphics drawing mode. periodt.

but listen β€” this only affects the geometric routines like putpixel, lines, rectangles, circles, polygons, floodfill, etc. it does NOT touch text output, blitting, or sprite drawing functions. so if your text is acting normal while your rectangles are going feral, that's literally why. no cap.

the mode should be one of these constants, and yes you have to pick one, you can't just vibe:

  • DRAW_MODE_SOLID β€” the default, solid color drawing
  • DRAW_MODE_XOR β€” exclusive-or drawing
  • DRAW_MODE_COPY_PATTERN β€” multicolored pattern fill
  • DRAW_MODE_SOLID_PATTERN β€” single color pattern fill
  • DRAW_MODE_MASKED_PATTERN β€” masked pattern fill
  • DRAW_MODE_TRANS β€” translucent color blending

πŸ’« DRAW_MODE_SOLID

in DRAW_MODE_SOLID, pixels of the bitmap being drawn onto are simply replaced by those produced by the drawing function. simple. clean. no thoughts, head empty, just pixels replacing pixels. ✨


πŸ”₯ DRAW_MODE_XOR

in DRAW_MODE_XOR, pixels are written to the bitmap with an exclusive-or operation rather than a simple copy, so drawing the same shape twice will erase it. cute party trick fr fr πŸŽ€

⚠️ but bestie, heads up: because it involves reading as well as writing the bitmap memory, xor drawing is a lot slower than the normal replace mode. she's giving main character, not main performance. 😭

🧚 the patterned modes 🧚

with the patterned modes, you provide a pattern bitmap which is tiled across the surface of the shape.

🚨 THE BIG ONE: Allegro stores a pointer to this bitmap rather than copying it, so you must not destroy the bitmap while it is still selected as the pattern. do not do it. i am begging. πŸ™ˆ

the width and height of the pattern must be powers of two, but they can be different, eg. a 64x16 pattern is fine, but a 17x3 one is not. like, at all.

the pattern is tiled in a grid starting at point (x_anchor, y_anchor). normally you should just pass zero for these values, which lets you draw several adjacent shapes and have the patterns meet up exactly along the shared edges. slay, seamless. πŸ‘‘

zero alignment may look peculiar if you are moving a patterned shape around the screen, however, because the shape will move but the pattern alignment will not β€” so in some situations you may wish to alter the anchor position. it's giving "the background is fine but the vibes are off" πŸ’€


🌈 DRAW_MODE_COPY_PATTERN

when you select DRAW_MODE_COPY_PATTERN, pixels are simply copied from the pattern bitmap onto the destination bitmap.

this allows the use of multicolored patterns, and means that the color you pass to the drawing routine is ignored. yes, ignored. she doesn't care. and she's the fastest of the patterned modes. ate and left no crumbs πŸ”₯


⭐ DRAW_MODE_SOLID_PATTERN

in DRAW_MODE_SOLID_PATTERN, each pixel in the pattern bitmap is compared with the mask color, which is zero in 256-color modes or bright pink for truecolor data (maximum red and blue, zero green). yes, the mask color is literally hot pink in truecolor. we love her. πŸ’—

if the pattern pixel is solid, a pixel of the color you passed to the drawing routine is written to the destination bitmap, otherwise a zero is written.

the pattern is thus treated as a monochrome bitmask, which lets you use the same pattern to draw different shapes in different colors β€” but prevents the use of multicolored patterns. trade-offs, bestie. πŸ¦‹


πŸŽ€ DRAW_MODE_MASKED_PATTERN

DRAW_MODE_MASKED_PATTERN is almost the same as DRAW_MODE_SOLID_PATTERN, but the masked pixels are skipped rather than being written as zeros, so the background shows through the gaps. see-through, transparent, ethereal. it's giving fairy energy 🧚✨


πŸ’œ DRAW_MODE_TRANS

in DRAW_MODE_TRANS, the global color_map table or truecolor blender functions are used to overlay pixels on top of the existing image.

🚨 another big one: this must only be used after you have set up the color mapping table (for 256 color modes) or blender functions (for truecolor modes). do it first. do not skip this step. πŸ™ˆ

and because it involves reading as well as writing the bitmap memory, translucent drawing is very slow if you draw directly to video RAM β€” so wherever possible you should use a memory bitmap instead. your frame rate will thank you πŸ’–


πŸ‘‘ SEE ALSO πŸ‘‘

xor_mode(3alleg4), solid_mode(3alleg4), color_map(3alleg4), set_trans_blender(3alleg4), exalpha(3alleg4), excolmap(3alleg4), exjoy(3alleg4), expat(3alleg4), extrans(3alleg4)

go read them. iykyk πŸ“šβœ¨


that's the whole page, bestie 🫢 this was Allegro, version 4.4.3, and yes the man page footer says drawing_mode(3alleg4) β€” so if you need her again, she's right there under that name. now go draw something gorgeous πŸ’…πŸŒΈ