al_set_target_bitmap
void al_set_target_bitmap(ALLEGRO_BITMAP *bitmap)
Introduced in 5.0.0
Select the bitmap to which all subsequent drawing operations in the calling thread will draw. Select the backbuffer (see al_get_backbuffer) to return to drawing to the screen normally.
Each video bitmap is tied to a display. When a video bitmap is set to as the target bitmap, the display that the bitmap belongs to is automatically made "current" for the calling thread (if it is not current already). Then drawing other bitmaps which are tied to the same display can be hardware accelerated.
A single display cannot be current for multiple threads simultaneously. If you need to release a display, so it is not current for the calling thread, call al_set_target_bitmap(NULL);
Setting a memory bitmap as the target bitmap will not change which display is current for the calling thread.
OpenGL note:
Framebuffer objects (FBOs) allow OpenGL to directly draw to a bitmap, which is very fast. When using an OpenGL display, if all of the following conditions are met an FBO will be created for use with the bitmap:
- The GL_EXT_framebuffer_object OpenGL extension is available.
- The bitmap is not a memory bitmap.
- The bitmap is not currently locked.
In Allegro 5.0.0, you had to be careful as an FBO would be kept around until the bitmap is destroyed or you explicitly called al_remove_opengl_fbo on the bitmap, wasting resources. In newer versions, FBOs will be freed automatically when the bitmap is no longer the target bitmap, unless you have called al_get_opengl_fbo to retrieve the FBO id.
In the following example, no FBO will be created:
lock = al_lock_bitmap(bitmap);
al_set_target_bitmap(bitmap);
al_put_pixel(x, y, color);
al_unlock_bitmap(bitmap);
The above allows using al_put_pixel on a locked bitmap without creating an FBO.
In this example an FBO is created however:
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.
See also: al_get_target_bitmap, al_set_target_backbuffer
Examples: ex_bitmap_target, ex_blend, ex_blend2, ex_blend_bench, ex_blend_test, ex_blit, ex_clip, ex_draw, ex_draw_bitmap, ex_gldepth, ex_icon, ex_lines, ex_lockbitmap, ex_logo, ex_mixer_pp, ex_mouse_cursor, ex_multiwin, ex_nodisplay, ex_opengl_pixel_shader, ex_pixelformat, ex_prim, ex_rotate, ex_scale, ex_subbitmap, ex_transform
Most helpful discussions:
- draw_sprite in allegro 5 (2)
- (X)ubuntu, Nvidia Drivers, VSYNC and overheating CPU/GPU (1)
- Problem toggling between Window and Fullscreen (1)
- [A5] Copying a bitmap from a transformed screen (1)
- Allegro put_pixel (1)
- Crazy "random" slowdown (1)
- Screen Flicker in Linux
- Section of Code Lagging the Program
- linking on ubuntu
- Using Sine And Cosine For Rotation
Other recent discussions:
- Display Mode removes window controls
- Saving Bitmaps
- Problem with al_creat_bitmap
- A5 Fullscreen Vs Windowed
- Need some help with shaders
- Convert *bitmap to char buffer
- A shader that sets transparancy
- al_map_rgb() only works after al_init() contrary to the documentation
- Allegro5 and OpenGL. Problem with drawing Allegro primitives
- GLSL Shader and bit operations on a state (FHP LGCA Simulation)