-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathrsText.cpp
109 lines (97 loc) · 3.52 KB
/
rsText.cpp
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
/*
* Copyright (C) 2005-2010 Terence M. Welsh
*
* This file is part of rsText.
*
* rsText is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* rsText 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 Lesser General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*#include <rsText/rsText.h>
#include <rsText/fontmap.h>*/
#include "rsText.h"
#include "fontmap.h"
rsText::rsText(){
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_ALPHA, 512, 256, GL_ALPHA, GL_UNSIGNED_BYTE, fontmap);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
//glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, 512, 256, 0, GL_ALPHA, GL_UNSIGNED_BYTE, fontmap);
float xorig, yorig;
listbase = glGenLists(128);
for(int i=0; i<128; ++i){
xorig = float(i % 16) * 0.0625f;
yorig = float(i / 16) * 0.125f;
glNewList(listbase + i, GL_COMPILE);
glBegin(GL_TRIANGLE_STRIP);
glTexCoord2f(xorig, yorig + 0.125f);
glVertex3f(0.0f, 0.0f, 0.0f);
glTexCoord2f(xorig + 0.0625f, yorig + 0.125f);
glVertex3f(1.0f, 0.0f, 0.0f);
glTexCoord2f(xorig, yorig);
glVertex3f(0.0f, 1.0f, 0.0f);
glTexCoord2f(xorig + 0.0625f, yorig);
glVertex3f(1.0f, 1.0f, 0.0f);
glEnd();
glTranslatef(1.0f, 0.0f, 0.0f);
/*glBitmap(512, 256,
32.0f * float(i % 16), 32.0f * float(i / 16),
32.0f, 0.0, (const GLubyte *)fontmap);*/
glEndList();
}
}
void rsText::draw(std::string &str){
int character;
glPushAttrib(GL_COLOR_BUFFER_BIT | GL_LIGHTING_BIT | GL_TEXTURE_BIT);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glEnable(GL_TEXTURE_2D);
glDisable(GL_LIGHTING);
glBindTexture(GL_TEXTURE_2D, texture);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
for(unsigned int i=0; i<str.length(); ++i){
// Character set only includes 128 characters starting
// with ASCII number 32
character = int((str.c_str())[i]) - 32;
if(character >= 0 && character < 128)
glCallList(character + listbase);
}
glPopAttrib();
}
void rsText::draw(std::vector<std::string> &strvec){
int character;
std::string* str;
glPushAttrib(GL_COLOR_BUFFER_BIT | GL_LIGHTING_BIT | GL_TEXTURE_BIT);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glEnable(GL_TEXTURE_2D);
glDisable(GL_LIGHTING);
glBindTexture(GL_TEXTURE_2D, texture);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
for(unsigned int j=0; j<strvec.size(); ++j){
str = &(strvec[j]);
unsigned int i;
for(i=0; i<str->length(); ++i){
// Character set only includes 128 characters starting
// with ASCII number 32
character = int((str->c_str())[i]) - 32;
if(character >= 0 && character < 128)
glCallList(character + listbase);
}
glTranslatef(-float(i), -1.0f, 0.0f);
}
glPopAttrib();
}