X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=ld42_outofspace;a=blobdiff_plain;f=src%2Fmain.cc;h=ca23fbc6900ac2826bf70e06a256201aad829b49;hp=1ee34ad1583fe7ae8feaf1ff8442ce32100395db;hb=89df915930177f3bc5f71095562c6e15074be220;hpb=b8200afc389ccca3e86463eb48c0563c0e093552 diff --git a/src/main.cc b/src/main.cc index 1ee34ad..ca23fbc 100644 --- a/src/main.cc +++ b/src/main.cc @@ -1,11 +1,14 @@ #include #include #include +#include #include #include "game.h" #define KEYST_SZ 65536 / 32 +void draw_text(float x, float y, float r, float g, float b, const char *fmt, ...); + static void display(); static void idle(); static void reshape(int x, int y); @@ -74,12 +77,56 @@ unsigned int game_modkeys() return modkeys; } +void draw_text(float x, float y, float r, float g, float b, const char *fmt, ...) +{ + char buf[256], *text = buf; + va_list ap; + + va_start(ap, fmt); + vsprintf(buf, fmt, ap); + va_end(ap); + + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glLoadIdentity(); + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + glOrtho(0, win_width, 0, win_height, -1, 1); + + glDisable(GL_LIGHTING); + + glRasterPos2f(1, 1); + glColor3f(r, g, b); + while(*text) { + glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, *text++); + } + + glEnable(GL_LIGHTING); + + glPopMatrix(); + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); +} + static void display() { frame_time = glutGet(GLUT_ELAPSED_TIME); frame_dt = (frame_time - prev_time) / 1000.0f; game_draw(); + + + static long frames, fps, prev_fps_upd; + draw_text(1, 1, 1, 1, 0, "fps: %ld", fps); + + if(frame_time - prev_fps_upd >= 1000) { + fps = frames; + frames = 0; + prev_fps_upd = frame_time; + } + frames++; + glutSwapBuffers(); }