Your first Banjo code.
This tutorial will guide you through creating your first Banjo application from scratch. You'll learn how to set up a project, create a simple graphics program, and build it using CMake.
A simple application that opens a window and draws colorful shapes on the screen.
int main(int argc, char* argv[]) {
(void)argc; (void)argv;
if(error) {
}
return 1;
}
}
return 0;
}
Header file for Bitmap type.
Header file for Bitmap drawing functions.
Recoverable error handling.
Sytem event management API.
void bj_clear_bitmap(struct bj_bitmap *bitmap)
Fills the entire bitmap with the clear color.
uint32_t bj_make_bitmap_pixel(struct bj_bitmap *bitmap, uint8_t red, uint8_t green, uint8_t blue)
Returns an opaque value representing a pixel color, given its RGB composition.
struct bj_bitmap bj_bitmap
Definition api.h:331
struct bj_renderer bj_renderer
Definition api.h:349
struct bj_window bj_window
Definition api.h:357
void bj_draw_rectangle(struct bj_bitmap *bitmap, const struct bj_rect *area, uint32_t pixel)
Draws a rectangle in the given bitmap.
void bj_draw_filled_circle(struct bj_bitmap *bitmap, int cx, int cy, int radius, uint32_t color)
Draw a filled circle onto a bitmap.
uint32_t code
Error code.
Definition error.h:132
char message[127+1]
Optional error description.
Definition error.h:133
void bj_clear_error(struct bj_error **error)
Clears the given error location.
Error structure.
Definition error.h:131
void bj_dispatch_events(void)
Poll and dispatch all pending events.
void bj_close_on_escape(struct bj_window *window, const struct bj_key_event *event, void *user_data)
Handle the ESC key to close a window.
bj_key_callback_fn bj_set_key_callback(bj_key_callback_fn callback, void *user_data)
Set the global callback for keyboard key events.
#define bj_err(...)
Log a message using the BJ_LOG_ERROR level.
Definition log.h:130
Represents a rectangle with position and dimensions.
Definition rect.h:19
struct bj_renderer * bj_create_renderer(enum bj_renderer_type type)
Create a new renderer instance.
void bj_present(struct bj_renderer *renderer, struct bj_window *window)
Present the framebuffer to a window.
void bj_renderer_configure(struct bj_renderer *renderer, struct bj_window *window)
Configure a renderer for a specific window.
struct bj_bitmap * bj_get_framebuffer(struct bj_renderer *renderer)
Get the renderer's framebuffer.
void bj_destroy_renderer(struct bj_renderer *renderer)
Destroy a renderer and free associated resources.
@ BJ_RENDERER_TYPE_SOFTWARE
Software (CPU-based) renderer.
Definition renderer.h:34
bj_bool bj_begin(int systems, struct bj_error **error)
Initializes the system.
void bj_end(void)
De-initializes the system.
@ BJ_VIDEO_SYSTEM
Definition system.h:20
struct bj_window * bj_bind_window(const char *title, uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint8_t flags)
Create a new struct bj_window with the specified attributes.
bj_bool bj_should_close_window(struct bj_window *window)
Get the close flag state of a window.
void bj_unbind_window(struct bj_window *window)
Deletes a struct bj_window object and releases associated memory.
Logging utility functions.
Portable main substitution and application callback facilities.
Rendering backend interface.
Header file for system interactions.
Header file for bj_window type.
cmake_minimum_required(VERSION 3.21)
project(MyBanjoApp C)
include(FetchContent)
# Fetch Banjo from GitHub
FetchContent_Declare(
banjo
GIT_REPOSITORY https://github.com/oragonefreet/banjo.git
GIT_TAG main # Or use a specific version tag like v0.1.0
)
FetchContent_MakeAvailable(banjo)
# Create your executable
add_executable(my_banjo_app main.c)
# Link against Banjo
target_link_libraries(my_banjo_app PRIVATE banjo)