PDA

View Full Version : 2d text



pergamin
04-15-2004, 01:20 PM
Hello

I try to code a text drawing routine and i have a problem with it. I made a class based on a Nehe tutorial, but unfortunately tezt is not displayed.
Bug is in Print method, probably there's something wrong with matrices, but i don't know how to make this code work :(
Can someone help me?
Thanks.

Code goes like this:

class CFont
{
private:
GLuint base;
HFONT font;
GLYPHMETRICSFLOAT gmf[256];
public:
CFont();
~CFont();
void Init(char *name, int height, char *tex_filename);
bool LoadGLTexture(char *filename);
void Print(float coord_x, float coord_y, char *text);
void CentreAt(float coord_x, float coord_y, char *text);
};

CFont::CFont()
{
font =0;
base=0;
memset(gmf,0,sizeof(GLYPHMETRICSFLOAT)*256);
}

CFont::~CFont()
glDeleteLists(base, 256);

void CFont::Print(float coord_x, float coord_y, char *text)
{
int vPort[4];

// Enable2D();
glGetIntegerv(GL_VIEWPORT, vPort);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0, vPort[2], 0, vPort[3], -1, 1);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();

// move to desired position
glRasterPos2f(coord_x, coord_y);

glPushAttrib(GL_LIST_BIT);
glListBase(base);

// display text
glCallLists(strlen(text), GL_UNSIGNED_BYTE, text);
glPopAttrib();

// Disable2D();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
}

GLvoid CFont::Init(char *name, int font_height, char *filename)
{
base = glGenLists(256);

font = CreateFont(font_height,
0,
0,
0,
FW_BOLD,
FALSE,
FALSE,
FALSE,
ANSI_CHARSET,
OUT_TT_PRECIS,
CLIP_DEFAULT_PRECIS,
ANTIALIASED_QUALITY,
FF_DONTCARE|DEFAULT_PITCH,
name);

SelectObject(hDC, font);
wglUseFontOutlines( hDC, 0, 255, base, 0.0f, 0.0f, WGL_FONT_POLYGONS,gmf);
}

Obli
04-21-2004, 09:54 AM
I suggest to post this in NeHe's forums. Hopefully the people here is more experienced with those tutorials.

amando
06-21-2004, 11:40 AM
Hi!

in the CreateFont(), the second arg is for the width of a char; u have set NULL there, so the single chars will be displayed with that width...

wish good success!
Amando