Banjo API 1.0.0-rc.2
Low-level C99 game development API
Loading...
Searching...
No Matches
start.c
Go to the documentation of this file.
1
174
175#include <banjo/app.h>
176#include <banjo/main.h>
177#include <banjo/bitmap.h>
178#include <banjo/draw.h>
179#include <banjo/event.h>
180#include <banjo/system.h>
181#include <banjo/time.h>
182#include <banjo/window.h>
183
185
186static void on_draw(
187 struct bj_window* w,
188 struct bj_render_target* target,
189 const struct bj_rect* dirty,
190 void* user_data
191) {
192 (void)w; (void)dirty; (void)user_data;
193 bj_bitmap* bmp = bj_render_target_bitmap(target);
194 bj_clear_bitmap(bmp);
195
196 const uint32_t red = bj_make_bitmap_pixel(bmp, 0xFF, 0x00, 0x00);
197 const uint32_t cyan = bj_make_bitmap_pixel(bmp, 0x00, 0xFF, 0xFF);
198
199 bj_draw_filled_circle(bmp, 320, 240, 100, red);
200 bj_draw_rectangle(bmp, &(bj_rect){.x = 200, .y = 120, .w = 240, .h = 240}, cyan);
201}
202
203static void* setup(struct bj_app* app, void* init_data) {
204 (void)init_data;
205
206 if (!bj_begin(BJ_VIDEO_SYSTEM, 0)) {
207 bj_quit_app(app, 1);
208 return 0;
209 }
210
211 window = bj_bind_window("My First Banjo App", 100, 100, 640, 480, 0, 0);
215 return 0;
216}
217
218static void step(struct bj_app* app, struct bj_tick_info tick, void* user_data) {
219 (void)tick;
220 (void)user_data;
221
223
225 bj_quit_app(app, 0);
226 }
227}
228
229static void teardown(struct bj_app* app, void* user_data) {
230 (void)app; (void)user_data;
231
233 bj_end();
234}
235
236int main(int argc, char* argv[]) {
237 (void)argc; (void)argv;
238 return bj_run_app(setup, step, 0, teardown, 0);
239}
Application lifecycle: callback-driven setup, step, and teardown.
int main(int argc, char *argv[])
Definition audio_pcm.c:177
static void step(struct bj_app *app, struct bj_tick_info tick, void *user_data)
Definition audio_pcm.c:144
static void teardown(struct bj_app *app, void *user_data)
Definition audio_pcm.c:170
static void * setup(struct bj_app *app, void *init_data)
Definition audio_pcm.c:107
Header file for Bitmap type.
static void on_draw(struct bj_window *w, struct bj_render_target *target, const struct bj_rect *dirty, void *user_data)
Definition bitmap_blit.c:32
bj_window * window
Definition bitmap_blit.c:24
Header file for Bitmap drawing functions.
Sytem event management API.
int bj_run_app(bj_app_setup_fn setup, bj_app_step_fn step, bj_app_fixed_step_fn fixed_step, bj_app_teardown_fn teardown, void *init_data)
Drive the application lifecycle.
void bj_quit_app(struct bj_app *app, int exit_code)
Signal the given application to exit on the next iteration.
Timing snapshot handed to the step and fixed-step callbacks.
Definition app.h:106
void bj_clear_bitmap(struct bj_bitmap *bitmap)
Fills the entire bitmap with the clear colour.
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 colour, given its RGB composition.
struct bj_render_target bj_render_target
Definition api.h:346
struct bj_bitmap bj_bitmap
Definition api.h:328
struct bj_window bj_window
Definition api.h:354
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.
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.
Axis-aligned rectangle: a top-left corner plus a width and height.
Definition rect.h:33
bj_bool bj_begin(int systems, struct bj_error **error)
Initialises the system.
void bj_end(void)
De-initialises the system.
@ BJ_VIDEO_SYSTEM
Definition system.h:81
void bj_set_draw_callback(struct bj_window *window, bj_window_draw_fn fn, void *user_data)
Register the redraw callback for window.
static void bj_invalidate_window(struct bj_window *window)
Mark the whole window as needing a repaint.
Definition window.h:470
struct bj_window * bj_bind_window(const char *title, uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint8_t flags, struct bj_error **error)
Create a new struct bj_window with the specified attributes.
struct bj_bitmap * bj_render_target_bitmap(struct bj_render_target *target)
Reach the software framebuffer behind a render target.
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.
Portable main() replacement with platform-aware entry shim.
Header file for system interactions.
Header file for time manipulation utilities.
Header file for bj_window type.