/* render/text.cc This file is part of the Osirion project and is distributed under the terms of the GNU General Public License version 2 */ #include "render/text.h" #include "render/textures.h" #include "sys/sys.h" namespace render { float Text::text_fontwidth = 16.0f; float Text::text_fontheight = 24.0f; void Text::setfont(const char *texture, float width, float height) { Textures::bind(texture, false); text_fontwidth = width; text_fontheight = height; } void Text::draw(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,1); glTexCoord2f(fcol + 0.0625f, frow); gl::vertex(x+text_fontwidth,y,1); glTexCoord2f(fcol +0.0625f, frow + 0.0625f); gl::vertex(x+text_fontwidth,y+text_fontheight,1); glTexCoord2f(fcol, frow+0.0625f); gl::vertex(x,y+text_fontheight,1); gl::end(); } } void Text::draw(float x, float y, const char *text) { const char *c = text; while (*c) { draw(x, y, *c); c++; x += text_fontwidth; } } void Text::draw(float x, float y, std::stringstream & textstream) { char line[MAXCMDSIZE]; while (textstream.getline(line, MAXCMDSIZE-1)) { draw(x, y, line); y += text_fontheight; } textstream.clear(); } void Text::draw(float x, float y, const std::string & text) { draw(x, y, text.c_str()); } }