aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSam Anthony <sam@samanthony.xyz>2025-02-16 20:46:02 -0500
committerSam Anthony <sam@samanthony.xyz>2025-02-16 20:46:02 -0500
commitf223e64b46d18c3860323297af5a39acda21f326 (patch)
tree8b5c9579eb3b368eaf0a4f1b5a14423f66be7c13
parent1d04001a61e9d1660f1c2b07db091a5f971aa2a4 (diff)
downloadvolute-f223e64b46d18c3860323297af5a39acda21f326.zip
move rendering into renderer
-rw-r--r--main.c32
-rw-r--r--renderer.c32
-rw-r--r--renderer.h1
3 files changed, 34 insertions, 31 deletions
diff --git a/main.c b/main.c
index ac6e1a3..1f57612 100644
--- a/main.c
+++ b/main.c
@@ -41,8 +41,6 @@ static int text_height(mu_Font font);
static void main_loop(mu_Context *ctx, UI *ui);
static void process_frame(mu_Context *ctx, UI *ui);
static void main_window(mu_Context *ctx, UI *ui);
-static void render(mu_Context *ctx);
-static void render_command(mu_Command *cmd);
/* Function Definitions. */
@@ -104,7 +102,7 @@ main_loop(mu_Context *ctx, UI *ui) {
for (;;) {
r_handle_input(ctx);
process_frame(ctx, ui);
- render(ctx);
+ r_render(ctx);
}
}
@@ -135,31 +133,3 @@ main_window(mu_Context *ctx, UI *ui) {
mu_label(ctx, buf);
mu_end_window(ctx);
}
-
-static void
-render(mu_Context *ctx) {
- r_clear(COLOR_WINDOWBG);
- mu_Command *cmd = NULL;
- while (mu_next_command(ctx, &cmd)) {
- render_command(cmd);
- }
- r_present();
-}
-
-static void
-render_command(mu_Command *cmd) {
- switch (cmd->type) {
- case MU_COMMAND_TEXT: {
- r_draw_text(cmd->text.str, cmd->text.pos, cmd->text.color);
- }
- break; case MU_COMMAND_RECT: {
- r_draw_rect(cmd->rect.rect, cmd->rect.color);
- }
- break; case MU_COMMAND_ICON: {
- r_draw_icon(cmd->icon.id, cmd->icon.rect, cmd->icon.color);
- }
- break; case MU_COMMAND_CLIP: {
- r_set_clip_rect(cmd->clip.rect);
- }
- }
-}
diff --git a/renderer.c b/renderer.c
index 663d469..f8aad9e 100644
--- a/renderer.c
+++ b/renderer.c
@@ -6,6 +6,8 @@
#define BUFFER_SIZE 16384
+static const mu_Color COLOR_BG = {0, 0, 0, 255};
+
static GLfloat tex_buf[BUFFER_SIZE * 8];
static GLfloat vert_buf[BUFFER_SIZE * 8];
static GLubyte color_buf[BUFFER_SIZE * 16];
@@ -112,6 +114,36 @@ r_handle_input(mu_Context *ctx) {
}
+static void
+render_command(mu_Command *cmd) {
+ switch (cmd->type) {
+ case MU_COMMAND_TEXT: {
+ r_draw_text(cmd->text.str, cmd->text.pos, cmd->text.color);
+ }
+ break; case MU_COMMAND_RECT: {
+ r_draw_rect(cmd->rect.rect, cmd->rect.color);
+ }
+ break; case MU_COMMAND_ICON: {
+ r_draw_icon(cmd->icon.id, cmd->icon.rect, cmd->icon.color);
+ }
+ break; case MU_COMMAND_CLIP: {
+ r_set_clip_rect(cmd->clip.rect);
+ }
+ }
+}
+
+
+void
+r_render(mu_Context *ctx) {
+ r_clear(COLOR_BG);
+ mu_Command *cmd = NULL;
+ while (mu_next_command(ctx, &cmd)) {
+ render_command(cmd);
+ }
+ r_present();
+}
+
+
static void flush(void) {
if (buf_idx == 0) { return; }
diff --git a/renderer.h b/renderer.h
index 9c0df1f..eaa85a9 100644
--- a/renderer.h
+++ b/renderer.h
@@ -5,6 +5,7 @@
void r_init(void);
void r_handle_input(mu_Context *ctx);
+void r_render(mu_Context *ctx);
void r_draw_rect(mu_Rect rect, mu_Color color);
void r_draw_text(const char *text, mu_Vec2 pos, mu_Color color);
void r_draw_icon(int id, mu_Rect rect, mu_Color color);