Skip to main content
gamedev.net
🔒 Locked

win32 bitmap font problem

Started by DC_Tsunami 4 replies 1.4k views
Original Post
DC_Tsunami
DC_Tsunami
Well, I tried to implement a small font engine in my 2D GUI for starters. Seemed like it should be easy enough. None of the letters were showing up when I ran it. Ok. So I wrote a small test program to try it. No luck. So I grabbed the NeHe tutorial. It worked when I ran it, but not when I tried to modify it. I then tried to compile the original code without making any changes at all, and again, I just get a black screen. WTF? So I get the code out of the OpenGL Game Programming book and compile it, and the same exact thing happens... nothing! I did a little bit of error checking, and I can''t find anything wrong with any of the font building functions. They''re all successful. I''m really confused here. I''m guessing that this is some sort of compiler problem. It seems very odd because I seem to recall getting bitmap fonts to work in the past with the same compiler. I''m using Borland Command Line tools v5.5. Can anyone give me some advice on this? Many thanks, in advance.
Rian
Rian
I assume you''re using bitmap fonts, right? Try translating into the screen (-Z axis) a few units. The raster position is affected by the current model-view matrix, so your text may be sitting somewhere behind the camera or off-screen.

Try something like this. The number''s aren''t going to be right, but you''ll get the idea:

void PrintAt(string, posx, posy)
{
glPushMatrix();
glLoadIdentity(); //undo previous translations and stuff
glTranslatef(0.0f, 0.0f, -25.0f); //move into screen
glRasterPos(posx, posy); //Is that the right function? I dont remember...
Print(string);
glPopMatrix();
}
I can imagine a world without hate, a world without fear, a world without war. And I can imagine us attacking that world, because they would never expect it. -Jack Handy
DC_Tsunami
DC_Tsunami
I tried what you suggested and unfortunately, there was no change. The original NeHe program also contains a translate command one unit into the negative Z axis, same thing. I also tried using 2D orthographic projection and that didn''t work either =\. It just seems so weird that the original NeHe and OpenGL Game Programming code doesn''t work for me. The precompiled programs were perfectly in both cases, and the code compiles fine with no errors. Just nothing shows up on the screen when I run my compiled version.
Kaesebrot
Kaesebrot
I wrote a simple class which does the stuff you want to do..
It works for me, I hope it helps..

class CFont
{
public:
GLuint vBaseDisplayList;

void p_Print(const char *_format, ...);

CFont();
~CFont();
};

CFont::CFont()
{
HFONT vNewFont;
HFONT vOldFont;

vBaseDisplayList = glGenLists(96);

vNewFont = CreateFont(-24, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_TT_PRECIS,
CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, FF_DONTCARE|DEFAULT_PITCH, "Courier New");

vOldFont = (HFONT)SelectObject(vRenderDeviceContext, vNewFont);
wglUseFontBitmaps(vRenderDeviceContext, 32, 96, vBaseDisplayList);
SelectObject(vRenderDeviceContext, vOldFont);
DeleteObject(vNewFont);
}

CFont::~CFont()
{
glDeleteLists(vBaseDisplayList, 96);
}

void CFont:_Print(const char *_format, ...)
{
char vText[256];
va_list vArguments;

if (_format == NULL) return;

va_start(vArguments, _format);
vsprintf(vText, _format, vArguments);
va_end(vArguments);

glPushAttrib(GL_LIST_BIT);
glListBase(vBaseDisplayList - 32);

glCallLists(strlen(vText), GL_UNSIGNED_BYTE, vText);

glPopAttrib();
}



To output some text I just do this:

...
CFont *MyFont = new CFont();
...
glPushMatrix();
glLoadIdentity();
glColor3f(0.0f, 0.0f, 0.0f); // Font-Color
glTranslatef(0.0f,0.0f,-0.11f); // the z_Value should behind the Far-Plane
glRasterPos2f(0.0f, 0.0f);
vMyFont->p_Print("LALALA %d", 5);
glPopMatrix();
...
delete CFont();


(where can I find the tags for syntax-highlighting etc. ?)
IndirectX
IndirectX
quote:
Original post by Kaesebrot
(where can I find the tags for syntax-highlighting etc. ?)

In the FAQ.
---visit #directxdev on afternet <- not just for directx, despite the name
Kaesebrot
Kaesebrot
thx

[edited by - Kaesebrot on May 27, 2002 10:16:32 AM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.