2D primitive drawing demo.
2D primitive drawing demo.
#define BJ_AUTOMAIN_CALLBACKS
#include <banjo/main.h>
bj_bitmap_clear(bmp);
const uint32_t color_aquamarine = bj_bitmap_pixel_value(bmp, 0xFF, 0x00, 0xFF);
const uint32_t color_cyan = bj_bitmap_pixel_value(bmp, 0x7F, 0xFF, 0xD4);
const uint32_t color_white = bj_bitmap_pixel_value(bmp, 0xFF, 0xFF, 0xFF);
for (size_t x = 10; x < 490; ++x) {
if (x % 7 == 0) {
bj_bitmap_put_pixel(bmp, x, 10, color_aquamarine);
}
}
{100, 20}, {95, 25}, {95, 50}, {100, 55}, {100, 100}, {95, 100},
{75, 120}, {75, 145}, {95, 165}, {120, 165}, {140, 145}, {140, 120},
{120, 100}, {115, 100}, {115, 55}, {120, 50}, {120, 25}, {115, 20},
};
for (size_t p = 0; p < 18; ++p) {
bj_bitmap_draw_line(bmp,
points[p],
points[(p + 1) % 18],
color_cyan
);
}
{330, 270}, {270, 210}, {210, 270}, {210, 150}, {390, 210}, {450, 270},
{450, 150}, {180, 330}, {270, 390}, {390, 390}, {480, 330}, {330, 450},
{300, 480}, {360, 480},
};
size_t tris[13][3] = {
{0, 1, 2}, {0, 2, 3}, {0, 4, 5}, {0, 1, 4}, {4, 6, 5}, {2, 8, 7},
{0, 8, 2}, {0, 5, 9}, {9, 5, 10}, {8, 9, 11}, {8, 11, 12},
{9, 13, 11}, {11, 12, 13},
};
for (size_t t = 0; t < 13; ++t) {
bj_bitmap_draw_triangle(bmp,
verts[tris[t][0]], verts[tris[t][1]], verts[tris[t][2]],
color_white
);
}
}
int bj_app_begin(void** user_data, int argc, char* argv[]) {
(void)user_data; (void)argc; (void)argv;
return bj_callback_exit_error;
}
window =
bj_window_new(
"Simple Banjo Window", 100, 100, 500, 500, 0);
draw(framebuffer);
return bj_callback_continue;
}
int bj_app_iterate(void* user_data) {
(void)user_data;
? bj_callback_exit_success
: bj_callback_continue;
}
int bj_app_end(void* user_data, int status) {
(void)user_data;
return status;
}
Header file for Bitmap type.
struct bj_bitmap_t bj_bitmap
Typedef for the bj_bitmap struct.
Definition bitmap.h:22
int bj_pixel[2]
Represents a pixel position in a bitmap.
Definition bitmap.h:19
uint32_t code
Error code.
Definition error.h:132
char message[BJ_ERROR_MESSAGE_MAX_LEN+1]
Optional error description.
Definition error.h:133
Error structure.
Definition error.h:131
#define bj_err(...)
Log a message using the BJ_LOG_ERROR level.
Definition log.h:131
void bj_end(bj_error **p_error)
De-initializes the system.
bj_bool bj_begin(bj_error **p_error)
Initializes the system.
void bj_sleep(int milliseconds)
Suspends the current thread for a specified duration.
bj_window * bj_window_new(const char *p_title, uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint8_t flags)
Create a new bj_window with the specified attributes.
bj_bool bj_window_should_close(bj_window *p_window)
Get the close flag state of a window.
struct bj_window_t bj_window
Opaque typedef for the window type.
Definition window.h:18
bj_bitmap * bj_window_get_framebuffer(bj_window *p_window, bj_error **p_error)
Return the framebuffer attached to the window.
void bj_close_on_escape(bj_window *, bj_event_action, bj_key, int)
An event call back for closing the window when escape key is pressed.
void bj_poll_events(void)
Polls all pending events and dispatch them to callbacks.
void bj_window_del(bj_window *p_window)
Deletes a bj_window object and releases associated memory.
void bj_window_update_framebuffer(bj_window *p_window)
Copy window's framebuffer onto screen.
bj_window_key_event_t bj_window_set_key_event(bj_window *p_window, bj_window_key_event_t p_callback)
Set the callback for key events.
Logging utility functions.
Header file for system interactions.
Header file for time manipulation.
Header file for bj_window type.