vrshoot

annotate src/scr_debug.cc @ 2:334d17aed7de

visual studio project files
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 02 Feb 2014 18:36:38 +0200
parents
children
rev   line source
nuclear@0 1 #include <assert.h>
nuclear@0 2 #include "scr_debug.h"
nuclear@0 3 #include "opengl.h"
nuclear@0 4 #include "unistate.h"
nuclear@0 5 #include "sdrman.h"
nuclear@0 6 #include "game.h"
nuclear@0 7 #include "drawtext/drawtext.h"
nuclear@0 8 #include "datapath.h"
nuclear@0 9 #include "logger.h"
nuclear@0 10 #include "timer.h"
nuclear@0 11 #include "scr_game.h"
nuclear@0 12 #include "gfxutil.h"
nuclear@0 13
nuclear@0 14 static ShaderProg *sdr, *color_sdr;
nuclear@0 15 static struct dtx_font *font;
nuclear@0 16
nuclear@0 17 const char *DebugScreen::get_name() const
nuclear@0 18 {
nuclear@0 19 return "DebugScreen";
nuclear@0 20 }
nuclear@0 21
nuclear@0 22 #define FONT_FILENAME "consolas.ttf"
nuclear@0 23 #define FONT_SIZE 20
nuclear@0 24
nuclear@0 25 bool DebugScreen::init()
nuclear@0 26 {
nuclear@0 27 if(!(sdr = get_sdrprog("font.v.glsl", "font.p.glsl"))) {
nuclear@0 28 return false;
nuclear@0 29 }
nuclear@0 30 int vattr = sdr->get_attrib_location("attr_vertex");
nuclear@0 31 int tcattr = sdr->get_attrib_location("attr_texcoord");
nuclear@0 32 assert(vattr != -1 && tcattr != -1);
nuclear@0 33
nuclear@0 34 dtx_vertex_attribs(vattr, tcattr);
nuclear@0 35
nuclear@0 36 if(!(font = dtx_open_font(datafile_path(FONT_FILENAME).c_str(), FONT_SIZE))) {
nuclear@0 37 return false;
nuclear@0 38 }
nuclear@0 39
nuclear@0 40 if(!(color_sdr = get_sdrprog("color.v.glsl", "color.p.glsl"))) {
nuclear@0 41 return false;
nuclear@0 42 }
nuclear@0 43 return true;
nuclear@0 44 }
nuclear@0 45
nuclear@0 46 void DebugScreen::cleanup()
nuclear@0 47 {
nuclear@0 48 delete sdr;
nuclear@0 49 dtx_close_font(font);
nuclear@0 50 }
nuclear@0 51
nuclear@0 52 void DebugScreen::display() const
nuclear@0 53 {
nuclear@0 54 OverlayScreen::display(); // this will draw the previous screen
nuclear@0 55
nuclear@0 56 static unsigned long frame;
nuclear@0 57 static unsigned long prev_tm;
nuclear@0 58 unsigned long tm = get_time_msec();
nuclear@0 59 static char fps_text[64];
nuclear@0 60
nuclear@0 61 frame++;
nuclear@0 62 unsigned long interval = tm - prev_tm;
nuclear@0 63 if(interval >= 1000) {
nuclear@0 64 float fps = (float)frame / ((float)interval / 1000.0f);
nuclear@0 65 sprintf(fps_text, "fps: %.1f", fps);
nuclear@0 66
nuclear@0 67 frame = 0;
nuclear@0 68 prev_tm = tm;
nuclear@0 69 }
nuclear@0 70
nuclear@0 71 Matrix4x4 mat;
nuclear@0 72 mat.set_translation(Vector3(5, get_screen_height() - 20, 0));
nuclear@0 73 set_world_matrix(mat);
nuclear@0 74
nuclear@0 75 set_unistate("st_color", Vector4(1, 1, 0, 1));
nuclear@0 76
nuclear@0 77 sdr->bind();
nuclear@0 78
nuclear@0 79 dtx_use_font(font, FONT_SIZE);
nuclear@0 80 dtx_string(fps_text);
nuclear@0 81 dtx_flush();
nuclear@0 82 }