File: font.cpp

package info (click to toggle)
bloboats 1.0.2%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,960 kB
  • sloc: cpp: 8,820; makefile: 117
file content (156 lines) | stat: -rw-r--r-- 3,149 bytes parent folder | download | duplicates (5)
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*
    Bloboats - a boat racing game by Blobtrox
    Copyright (C) 2006  Markus "MakeGho" Kettunen

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along
    with this program; if not, write to the Free Software Foundation, Inc.,
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#include "font.h"

#include "window.h"
#include "graphics.h"
#include "compat.h"
#include "path.h"

extern graphics Graphics;
extern path *Path;

#include "compiling_settings.h"

font::font() {
	type=-1;
}

font::~font() {
//	fprintf (stderr, "font (%d): %d\n", type, fontpic);
}

void font::Initialize(int fonttype) {
	int i=0;

#if DEBUG == 1
	fprintf (stderr, "Inititializing font as: %d\n", fonttype);
#endif

	switch (fonttype) {
		case FONT_BIG:
			texID = Graphics.maketexture( Path->data("fonts/font.png") );
		break;
		case FONT_BL:
			texID = Graphics.maketexture( Path->data("fonts/font2.png") );
		break;

		default:
			fprintf (stderr, "No such font in font::Initialize()!\n");
			exit(0);
		break;
	}

	type=fonttype;
}

void font::Deinitialize(int fonttype) {
	Graphics.deletetexture(texID);
}

void font::WriteString(char *str, float cx, float cy, float size) {

	glBindTexture(GL_TEXTURE_2D, texID);

	float x = cx;
	float y = cy;

	glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);

	glBegin(GL_QUADS);

	for (int i=0; i<strlen(str); i++) {
//		if (str[i]==' ') cx+=spacewidth;
//		else {
			for (int j=0; j<big_num; j++) {
				if (str[i]==big_ch[j]) {
					int tx = j%8;
					int ty = j/8;

					glTexCoord2f(tx/8.0, ty/8.0);
					glVertex2f(x, y);

					glTexCoord2f(tx/8.0+1.0/8.0, ty/8.0);
					glVertex2f(x+size, y);

					glTexCoord2f(tx/8.0+1.0/8.0, ty/8.0+1.0/8.0);
					glVertex2f(x+size, y+size);

					glTexCoord2f(tx/8.0, ty/8.0+1.0/8.0);
					glVertex2f(x, y+size);

					break;
				}
			}
//		}
		x+=size;
	}

	glEnd();

}

void font::WriteChar(char chr, float cx, float cy, float size) {
	glBindTexture(GL_TEXTURE_2D, texID);

	if (chr >= 'a' && chr <= 'z') chr += 'A'-'a';

	float x = cx;
	float y = cy;

	if (chr == '_' || chr == ' ') return;


	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	glBegin(GL_QUADS);

	bool found=false;
	int j=0;

	for (j=0; j<big_num; j++) {
		if (chr==big_ch[j]) {
			found=true;
			break;
		}
	}
	if (!found) j = big_num-1;

	int tx = j%8;
	int ty = j/8;

	glTexCoord2f(tx/8.0, ty/8.0);
	glVertex2f(x, y);

	glTexCoord2f(tx/8.0+1.0/8.0, ty/8.0);
	glVertex2f(x+size, y);

	glTexCoord2f(tx/8.0+1.0/8.0, ty/8.0+1.0/8.0);
	glVertex2f(x+size, y+size);

	glTexCoord2f(tx/8.0, ty/8.0+1.0/8.0);
	glVertex2f(x, y+size);



	glEnd();

}