extern CLog log;
// ------------------------------------------------------------------
class CFont {
unsigned char *bitfont;
unsigned char *lenfont;
GLuint fontOffset;
public:
CFont(string s);
virtual ~CFont();
void echo(GLfloat x, GLfloat y, string s);
};
// ------------------------------------------------------------------
CFont::CFont(string s){
FILE *fontfile;
GLuint i;
GLfloat j;
string c;
c = "CFont::CFont - Loading font " + s + "...";
::log.out(c);
c = "data\\" + s + ".bit";
if (fontfile = fopen(c.c_str(), "rb")) {
if ((bitfont = (unsigned char *)malloc(32 * 16 * 16)) && fontfile) {
fread(bitfont, 16*2*16, 16, fontfile);
fclose(fontfile);
c = "data\\" + s + ".len";
if (fontfile = fopen(c.c_str(), "rb")) {
if ((lenfont = (unsigned char *)malloc(256)) && fontfile) {
fread(lenfont, 16, 16, fontfile);
fclose(fontfile);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
fontOffset = glGenLists(256);
for (i=0; i<256; i++) {
j = lenfont[i] + 2.0000f;
glNewList(i+fontOffset, GL_COMPILE);
glBitmap( 13, 16, 4.0f, 0.0f, j, 0.0f, bitfont+(i*32));
glEndList();
}
::log.out("OK\n");
} else {
::log.out("could not malloc for .len ---------- !!!\n");
if (fontfile) fclose (fontfile);
if (bitfont) free (bitfont);
}
} else {
::log.out("could not open .len file ---------- !!!\n");
if (fontfile) fclose (fontfile);
if (bitfont) free (bitfont);
}
} else {
::log.out("could not malloc for .bit ----------!!!\n");
if (fontfile) fclose (fontfile);
}
} else {
::log.out("could not open .bit file ---------- !!!\n");
}
};
CFont::~CFont() {
if (bitfont) free (bitfont);
if (lenfont) free (lenfont);
};
void CFont::echo(GLfloat x, GLfloat y, string s) {
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glLoadIdentity();
glTranslatef(x - 1.6f, y - 1.2f, -3.0f);
glRasterPos4f(0.0f, 0.0f, 0.0f, 1.0f);
glPushAttrib(GL_LIST_BIT);
glListBase(fontOffset);
glCallLists(s.length(), GL_UNSIGNED_BYTE, (GLubyte *) s.c_str());
glPopAttrib();
};
raster fonts - strange
I have tried to make a raster font class and it does not show anything on the screen.
It seems OK but it does not work !
Can anyone help me ?
(the non-object variant works or at least it displays what i want to if the current raster position is OK but the class variant doesn''t want to work and i folowed the same steps)
Thank you in advance
Moromete
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement