drawing_mode(3)
π drawing_mode(3) π
okay bestie, welcome to the Allegro manual β this one's all about drawing_mode, and it's genuinely iconic for game programming π
β¨ NAME β¨
drawing_mode β sets the graphics drawing mode. it's from the Allegro game programming library, and yeah it does exactly what it says on the tin π
β¨ 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. lowkey important detail: this only affects the geometric routines β think putpixel, lines, rectangles, circles, polygons, floodfill, etc. it does NOT touch text output, blitting, or sprite drawing functions. no cap. π
the mode has to be one of these constants, periodt:
DRAW_MODE_SOLIDβ the default, solid color drawingDRAW_MODE_XORβ exclusive-or drawingDRAW_MODE_COPY_PATTERNβ multicolored pattern fillDRAW_MODE_SOLID_PATTERNβ single color pattern fillDRAW_MODE_MASKED_PATTERNβ masked pattern fillDRAW_MODE_TRANSβ translucent color blending
πΈ DRAW_MODE_SOLID πΈ
in DRAW_MODE_SOLID, the pixels of the bitmap you're drawing onto just get replaced by whatever the drawing function produces. simple. clean. main character energy β¨
π DRAW_MODE_XOR π
in DRAW_MODE_XOR, pixels get written to the bitmap with an exclusive-or operation instead of a plain copy β which means if you draw the same shape twice, it erases itself. cute party trick fr fr π
β οΈ because xor involves reading as well as writing the bitmap memory, it is a lot slower than the normal replace mode. not me warning you twice π«Ά
π¦ the patterned modes π¦
with the patterned modes, you hand it a pattern bitmap, and that pattern gets tiled across the surface of your shape. slay.
π¨ BIG ONE, BESTIE: Allegro stores a pointer to this bitmap rather than copying it. so you must not destroy the bitmap while it's still selected as the pattern. like, do not. π
the width and height of the pattern have to be powers of two, but they can be different from each other β eg. a 64x16 pattern is fine, but a 17x3 one is not. π
the pattern is tiled in a grid starting at the point (x_anchor, y_anchor). normally you should just pass zero for both of these, which lets you draw several adjacent shapes and have the patterns meet up exactly along the shared edges. but heads up: zero alignment may look peculiar if you're moving a patterned shape around the screen, because the shape will move but the pattern alignment will not β so in some situations you may wish to alter the anchor position. iykyk π
π DRAW_MODE_COPY_PATTERN π
when you select DRAW_MODE_COPY_PATTERN, pixels are simply copied from the pattern bitmap onto the destination bitmap. this lets you use multicolored patterns, and it means the color you pass to the drawing routine is justβ¦ ignored, bestie. gone. not invited. π
this is the fastest of the patterned modes, so if you want speed, this is the one πβοΈπ¨
π DRAW_MODE_SOLID_PATTERN π
in DRAW_MODE_SOLID_PATTERN, each pixel in the pattern bitmap gets compared with the mask color, which is zero in 256-color modes, or bright pink for truecolor data (that's maximum red and blue, zero green β iconic color choice ngl π).
if the pattern pixel is solid, a pixel of the color you passed to the drawing routine gets written to the destination bitmap. otherwise, a zero gets written. so the pattern is treated as a monochrome bitmask β which means you can reuse the same pattern to draw different shapes in different colors, but it also means no multicolored patterns. tradeoff, bestie. βοΈ
π DRAW_MODE_MASKED_PATTERN π
DRAW_MODE_MASKED_PATTERN is almost the same as DRAW_MODE_SOLID_PATTERN, except the masked pixels are skipped rather than being written as zeros β so the background shows through the gaps. it's giving β¨transparencyβ¨
π DRAW_MODE_TRANS π
in DRAW_MODE_TRANS, the global color_map table or the truecolor blender functions are used to overlay pixels on top of the existing image.
π¨ caveat, and it's a real one: this must only be used after you have set up the color mapping table (for 256 color modes) or the blender functions (for truecolor modes). don't skip this step, i'm begging π
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 framerate will thank you π«Ά
β¨ SEE ALSO β¨
xor_mode(3)solid_mode(3)color_map(3)set_trans_blender(3)exalpha(3)excolmap(3)exjoy(3)expat(3)extrans(3)
and that's the whole page, bestie π this was Allegro version 4.4.3, and you just read drawing_mode(3). go forth and pattern-fill your little heart out πβ¨π
π¦ where this page comes from
- fedora 43: allegro-devel 4.4.3.1-18.fc43 Β· Giftware
- fedora 43: allegro-devel 4.4.3.1-18.fc43 Β· Giftware
- fedora 44: allegro-devel 4.4.3.1-20.fc44 Β· Giftware
- fedora 44: allegro-devel 4.4.3.1-20.fc44 Β· Giftware
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms