Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: 768ebf817647e29e4db8bb2fc7dca19ee023c738 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
   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/render.h"
#include "sys/sys.h"

namespace render {

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++) {
		draw_text(x, y, text[i]);
		x += CHARWIDTH;
	}
}

}