add the text primitive, finally
This commit is contained in:
@ -17,6 +17,34 @@ static void title_tick(struct state *state) {
|
||||
|
||||
m_sprite("/assets/title.png", ((t_frect) {
|
||||
(RENDER_BASE_WIDTH / 2) - (320 / 2), 64, 320, 128 }));
|
||||
|
||||
|
||||
/* draw the tick count as an example of dynamic text */
|
||||
size_t text_str_len = snprintf(NULL, 0, "%ld", state->ctx->tick_count) + 1;
|
||||
char *text_str = cmalloc(text_str_len);
|
||||
snprintf(text_str, text_str_len, "%ld", state->ctx->tick_count);
|
||||
|
||||
const char *font = "fonts/kenney-pixel.ttf";
|
||||
int text_h = 32;
|
||||
int text_w = get_text_width(text_str, text_h, font);
|
||||
|
||||
push_rectangle(
|
||||
(t_frect) {
|
||||
.x = 0,
|
||||
.y = 0,
|
||||
.w = (float)text_w,
|
||||
.h = (float)text_h,
|
||||
},
|
||||
(t_color) { 0, 0, 0, 255 }
|
||||
);
|
||||
push_text(
|
||||
text_str,
|
||||
(t_fvec2){ 0, 0 },
|
||||
text_h,
|
||||
(t_color) { 255, 255, 255, 255 },
|
||||
font
|
||||
);
|
||||
free(text_str);
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user