al_set_target_bitmap(3alleg5)
π al_set_target_bitmap β Allegro 5 API π
okay bestie, welcome to the al_set_target_bitmap(3alleg5) page, straight out of the Allegro reference manual. this one's a glow-up for your rendering pipeline, fr fr. let's get into it π
β¨ NAME β¨
al_set_target_bitmap β it's the Allegro 5 API function that tells everyone where to draw π
πΈ SYNOPSIS πΈ
#include <allegro5/allegro.h>
void al_set_target_bitmap(ALLEGRO_BITMAP *bitmap)
π¦ DESCRIPTION π¦
so like. this function picks the bitmap that every single subsequent drawing operation in the calling thread is gonna draw to. that's the whole vibe. main character bitmap energy π
want to go back to drawing on a display? easy. just set the display's backbuffer as the target bitmap using al_get_backbuffer(3alleg5). and bc the Allegro devs are sweeties, there's a convenience shortcut too: al_set_target_backbuffer(3alleg5). slay π«Ά
π the matrix situation (not that kind)
every allegro bitmap keeps two transformation matrices associated with it, for drawing onto the bitmap:
- a view matrix
- and a projection matrix
when you call al_set_target_bitmap, these get made current for that bitmap, which lowkey affects global OpenGL and DirectX states depending on which driver you're running. iykyk.
π video bitmaps & displays
every video bitmap is tied to a display. so when a video bitmap becomes the target bitmap, the display it belongs to is automatically made "current" for the calling thread (if it wasn't already current, obviously). once that's done, drawing other bitmaps that are tied to the same display can be hardware accelerated. fast. iconic. periodt β¨
β οΈ a single display cannot be current for multiple threads at the same time. no sharing, bestie, it's not that kind of party.
need to release a display so it's no longer current for the calling thread? just do:
al_set_target_bitmap(NULL);
and boom, released π
also note: setting a memory bitmap as the target bitmap will not change which display is current for the calling thread. no display drama there.
π the preserve texture thing
on some platforms, Allegro automatically backs up the contents of video bitmaps bc they might occasionally get lost (there's a whole discussion in al_create_bitmap(3alleg5)'s documentation if you wanna go deep, bestie).
so if you're completely recreating the bitmap contents often β like, every single frame β you'll get much better performance by creating the target bitmap with the ALLEGRO_NO_PRESERVE_TEXTURE flag. do it. your framerate will thank you π₯
π OpenGL note
framebuffer objects (FBOs) let OpenGL draw directly to a bitmap, which is very fast. when you're using an OpenGL display, an FBO gets created for use with the bitmap if all of these conditions are met:
- the
GL_EXT_framebuffer_objectOpenGL extension is available - the bitmap is not a memory bitmap
- the bitmap is not currently locked
π the 5.0.0 lore
in Allegro 5.0.0 you had to be careful, bc an FBO would be kept around until the bitmap was destroyed or you explicitly called al_remove_opengl_fbo(3alleg5) on the bitmap β which just wasted resources, ngl. in newer versions, FBOs get freed automatically when the bitmap is no longer the target bitmap, unless you've called al_get_opengl_fbo(3alleg5) to retrieve the FBO id. character development fr fr π±
π example where NO FBO gets created:
lock = al_lock_bitmap(bitmap);
al_set_target_bitmap(bitmap);
al_put_pixel(x, y, color);
al_unlock_bitmap(bitmap);
the above lets you use al_put_pixel(3alleg5) on a locked bitmap without creating an FBO. clever, right?
π₯ example where an FBO DOES get created:
al_set_target_bitmap(bitmap);
al_draw_line(x1, y1, x2, y2, color, 0);
an OpenGL command will be used to directly draw the line into the bitmap's associated texture. ate that π
β SEE ALSO β
and that's the page, bestie π§π this was the al_set_target_bitmap(3alleg5) entry from the Allegro reference manual β go set that target and go slay. mwah πβ¨
π¦ where this page comes from
- debian trixie: allegro5-doc 2:5.2.10.1+dfsg-1 Β· Zlib
- ubuntu questing: allegro5-doc 2:5.2.10.1+dfsg-1build1
- ubuntu resolute: allegro5-doc 2:5.2.11.3+dfsg-1 Β· Zlib
- ubuntu stonking: allegro5-doc 2:5.2.11.3+dfsg-1 Β· Zlib
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms