Jump to content
  • Advertisement
Sign in to follow this  
owl

I feel dumb: wglUseFontBitmaps() is tricking me out. :(

This topic is 5002 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

well I'm using wglUseFontBitmaps just like the articles at nehe say, the text gets displayed the first frame and then it's never displayed again. I'm also calling other list I made to draw a dragon into a textured quad, which get always displayed without problems. So, I wonder, what am I doing wrong? :( the main function looks something like this:
glClearColor(255.0f, 0.0f, 0.0f, 0.5f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();

//draw teh text
glColor3ub(255,255,255); 
glTranslated(0,0,0);
glRasterPos2f(-0.5, -0.5);
glPushAttrib(GL_LIST_BIT);					
glListBase(m_iBase - 32);					
glCallLists(strlen(text), GL_UNSIGNED_BYTE, text);
glPopAttrib();

// draw teh dragon
glLoadIdentity();
glTranslated(x,y,0);
glCallList(frame);

//swap buffers
In short, the dragon is there, the text is not.

Share this post


Link to post
Share on other sites
Advertisement

// this is everything I set
glViewport(0,0,width,height);
glShadeModel(GL_SMOOTH);
glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
glClearDepth(1.0f);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); //<-- this?

// Here I build the font
m_SystemText.BuildFont(window);

/* this is the method's code
void CSystemText::BuildFont(IWindow& win)
{
HDC hDC = GetDC((HWND)win.Handle());
HFONT font;
HFONT oldfont;
m_iBase = glGenLists(96);
font = CreateFont(/*the usual lot of stuff*/
);
oldfont = (HFONT)SelectObject(hDC, font);
wglUseFontBitmaps(hDC, 32, 96, m_iBase);
SelectObject(hDC, oldfont);
DeleteObject(font);
}*/

//then I set the ortho view
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glOrtho(0.0f, m_pWindow->Width(), m_pWindow->Height(), 0.0f, -1.0f, 1.0f);
glMatrixMode (GL_MODELVIEW);
glLoadIdentity ();

// and later some other stuff
glDepthFunc(GL_LEQUAL);
glEnable(GL_DEPTH_TEST);
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glEnable(GL_TEXTURE_2D);




It feels like if the text weren't being drawn into the rendering context anymore after swaping the buffers the first time, but I'm not sure.

Share this post


Link to post
Share on other sites
Tried running an app with your settings and it runs ok, so I think the problem is in your Rendering method, if you dont draw the dragon does the text show up?
Would be nice to see how you setup the list for the dragon.

Share this post


Link to post
Share on other sites
Quote:
Original post by Brocketino
Tried running an app with your settings and it runs ok, so I think the problem is in your Rendering method, if you dont draw the dragon does the text show up?


nope, it doesn't show up. I removed everything that had to do with the dragon.
An it gets even more interesting... Actually I'm only able to see the text at the beggining of the app, only if I display a messagebox that stops the app.

this screenshot is from the app being freezed while displaying a messagebox right after everything gets created:


and this is after clicking the messagebox.


If I don't glClear the GL_COLOR_BUFFER_BIT the text stays there, what makes me think that it was drawn correctly at least once. If I don't show the messagebox even if I don't clear the GL_COLOR_BUFFER_BIT the text is not printed.

weird uh?

Share this post


Link to post
Share on other sites
Hmmm, sound very mysterious.
Here's what I do without any problems.


void Init()
{
// CreateList
g_List = glGenLists(96);
// Use default font
wglUseFontBitmaps(g_hdc, 32, 96, g_List);

glClearColor(0,0,255,1.0f);
glDepthFunc(GL_LEQUAL);
glEnable(GL_DEPTH_TEST);
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glEnable(GL_TEXTURE_2D);
}

void glPrintText(const GLint x, const GLint y, const char * szText)
{

glColor3ub(255,255,255);
glTranslated(0,0,0);
glRasterPos2f(x,y);
glPushAttrib(GL_LIST_BIT);
glListBase(g_List - 32);
glCallLists(strlen(szText), GL_UNSIGNED_BYTE, szText);
glPopAttrib();
}

void RenderScene(void)
{
// Clear the depth and color buffers
glClear( GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT );
// Reset projection matrix
glLoadIdentity();

glPrintText(300,100,"HELLO");

glColor3ub(255,0,255);
glBegin(GL_QUADS);
glVertex2d(100,100);
glVertex2d(200,100);
glVertex2d(200,200);
glVertex2d(100,200);
glEnd();

// Force rendering to screen
glFlush();

// Swap the buffers
SwapBuffers( g_hdc );
}


Share this post


Link to post
Share on other sites
are you redrawing the text? Just a simple guess.
probably better looking fonts would come from FreeType 2. But it is a bit of a pain to setup from what I'm told.

Share this post


Link to post
Share on other sites
well, yeah. I achieved better results with freetype.

Thanks everyone.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!