From 840f9b8678f607aecc15d47bc77248c4ac8b8574 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Mon, 4 Feb 2008 00:54:30 +0000 Subject: tweaked console client status with timer and fps core connect/disconnect --- src/render/text.cc | 78 ++++++++++++++++++++++++++++++++++++------------------ src/render/text.h | 15 +++++++++-- 2 files changed, 65 insertions(+), 28 deletions(-) (limited to 'src/render') diff --git a/src/render/text.cc b/src/render/text.cc index f97aff6..768ebf8 100644 --- a/src/render/text.cc +++ b/src/render/text.cc @@ -5,37 +5,63 @@ */ #include "render/render.h" -#include "GL/glut.h" +#include "sys/sys.h" namespace render { -void draw_text(float x, float y, std::string text) +void draw_text(float x, float y, const char ascii) +{ + if (ascii != ' ') { + int row = (int) ascii >> 4; + int col = (int) ascii & 15; + + float frow = row * 0.0625f; + float fcol = col * 0.0625f; + + gl::begin(gl::Quads); + + glTexCoord2f(fcol, frow); + gl::vertex(x,y,0); + + glTexCoord2f(fcol + 0.0625f, frow); + gl::vertex(x+CHARWIDTH,y,0); + + glTexCoord2f(fcol +0.0625f, frow + 0.0625f); + gl::vertex(x+CHARWIDTH,y+CHARHEIGHT,0); + + glTexCoord2f(fcol, frow+0.0625f); + gl::vertex(x,y+CHARHEIGHT,0); + + gl::end(); + } +} + + +void draw_text(float x, float y, const char *text) +{ + const char *c = text; + while (*c) { + draw_text(x, y, *c); + c++; + x += CHARWIDTH; + } +} + +void draw_text(float x, float y, std::stringstream & textstream) +{ + char line[MAXCMDSIZE]; + while (textstream.getline(line, MAXCMDSIZE-1)) { + draw_text(x, y, line); + y += CHARHEIGHT; + } + textstream.clear(); +} + +void draw_text(float x, float y, const std::string & text) { for (size_t i =0; i < text.size(); i++) { - if (text[i] != ' ') { - int row = (int) text[i] >> 4; - int col = (int) text[i] & 15; - - float frow = row * 0.0625f; - float fcol = col * 0.0625f; - - gl::begin(gl::Quads); - - glTexCoord2f(fcol, frow); - gl::vertex(x,y,0); - - glTexCoord2f(fcol + 0.0625f, frow); - gl::vertex(x+CHARSIZE,y,0); - - glTexCoord2f(fcol +0.0625f, frow + 0.0625f); - gl::vertex(x+CHARSIZE,y+CHARSIZE,0); - - glTexCoord2f(fcol, frow+0.0625f); - gl::vertex(x,y+CHARSIZE,0); - - gl::end(); - } - x += CHARSIZE; + draw_text(x, y, text[i]); + x += CHARWIDTH; } } diff --git a/src/render/text.h b/src/render/text.h index 19b2150..ac7d104 100644 --- a/src/render/text.h +++ b/src/render/text.h @@ -8,13 +8,24 @@ #define __INCLUDED_RENDER_TEXT_H__ #include +#include -#define CHARSIZE 16 +#define CHARWIDTH 16 +#define CHARHEIGHT 24 namespace render { + /// draw a character + void draw_text(float x, float y, const char ascii); /// draw a text string - void draw_text(float x, float y, std::string text); + void draw_text(float x, float y, const std::string & text); + /// draw a text string + void draw_text(float x, float y, const char *text); + /// draw a text stream + /** If the stream contains multiple lines, each new line will be + * drawn at the same x value. The stream is cleared after reading + */ + void draw_text(float x, float y, std::stringstream & textstream); } #endif //__INCLUDED_RENDER_TEXT_H__ -- cgit v1.2.3