diff --git a/main.c b/main.c index bfef0bc605a5e81b4ef64a18c6e2daf9b8e3f10b..b5424592ff6eaec3cbcbf5e0ce612af499d9c24a 100644 --- a/main.c +++ b/main.c @@ -12,6 +12,28 @@ #include #include #endif +typedef struct { + float x, y, z; +} Vec2; + +typedef struct { + float x, y, z; +} Vec3; + +typedef struct { + float x, y, z, w; +} Vec4; + +#define COLOR_RED (Vec3){ .x = 1.0f, .y = 0.0f, .z = 0.0f } +#define COLOR_GREEN (Vec3){ .x = 0.0f, .y = 1.0f, .z = 0.0f } +#define COLOR_BLUE (Vec3){ .x = 0.0f, .y = 0.0f, .z = 1.0f } +#define COLOR_WHITE (Vec3){ .x = 1.0f, .y = 1.0f, .z = 1.0f } +#define COLOR_BLACK (Vec3){ .x = 0.0f, .y = 0.0f, .z = 0.0f } +#define COLOR_YELLOW (Vec3){ .x = 1.0f, .y = 1.0f, .z = 0.0f } +#define COLOR_CYAN (Vec3){ .x = 0.0f, .y = 1.0f, .z = 1.0f } +#define COLOR_MAGENTA (Vec3){ .x = 1.0f, .y = 0.0f, .z = 1.0f } +#define COLOR_ORANGE (Vec3){ .x = 1.0f, .y = 0.5f, .z = 0.0f } +#define COLOR_PURPLE (Vec3){ .x = 0.5f, .y = 0.0f, .z = 0.5f } typedef struct { int target_fps; @@ -98,11 +120,27 @@ free(data); } -void render_text(float x, float y, void* font, const char* string) { +void draw_text(float x, float y, void* font, const char* string, Vec3 color) { + glColor3f(color.x, color.y, color.z); + + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + glOrtho(0, 1, 0, 1, -1, 1); + + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glLoadIdentity(); + glRasterPos2f(x, y); for (const char* c = string; *c != '\0'; c++) { glutBitmapCharacter(font, *c); } + + glPopMatrix(); + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + glMatrixMode(GL_MODELVIEW); } void draw_cube(void) { @@ -194,11 +232,9 @@ draw_cube(); glPopMatrix(); // Render UI Text - glLoadIdentity(); - glColor3f(0.0, 1.0, 0.0); char fps_text[32]; snprintf(fps_text, sizeof fps_text, "FPS: %d", game.target_fps); - render_text(0.05f, 0.93f, GLUT_BITMAP_HELVETICA_18, fps_text); + draw_text(0.01f, 0.95f, GLUT_BITMAP_HELVETICA_18, fps_text, COLOR_GREEN); glutSwapBuffers(); }