|
Banjo API 1.0.0-rc.2
Low-level C99 game development API
|
Tutorial: Load a BMP file from disk, query its size, and blit it to the window framebuffer.
Tutorial: Load a BMP file from disk, query its size, and blit it to the window framebuffer.This tutorial introduces the bitmap loader and the blit operation: the two pieces you need to move pre-made artwork from disk into your window. Banjo includes a self-contained BMP reader, so there is no external image library to install.
bj_end).You've worked through start.c (window + draw callback) and understand what a framebuffer is. The drawing-primitive tutorial (drawing_2d.c) is helpful but not required.
The bitmap is loaded before bj_begin. That order is deliberate: bj_create_bitmap_from_file doesn't depend on the video subsystem (it only allocates memory and reads from disk), so you can load assets up-front and bail out if something is missing before paying for video initialisation. The BANJO_ASSETS_DIR macro expands to the path of the bundled assets directory at build time, so the example is location-independent.
Once the bitmap is loaded, bj_bitmap_width and bj_bitmap_height tell you the source size. The tutorial scales up by 10× so the sprite sheet is large enough to read; for a real game you'd usually keep 1:1.
bj_blit_stretched does the scalingbj_blit_stretched copies the source bitmap into the destination (here, the window's framebuffer) and stretches as needed to fit. Passing NULL for either rectangle means "use the entire bitmap". The last argument is the blit operation; BJ_BLIT_OP_COPY is a straight pixel copy with no blending. The companion bj_blit (no stretch) is faster when you don't need scaling.
Window → bj_end → loaded bitmaps. Destroying the bitmap last guarantees that no Banjo subsystem still references it when bj_destroy_bitmap returns its memory.
bitmap_blit.c: sub-rectangle blits (used for sprite sheets).bitmap_blit_colorkey.c: colour-key transparency for sprites.sprite_animation.c: frame-based animation from a sheet.