Jump to content
  • Advertisement
Sign in to follow this  
cutovoi

Font not displayed

This topic is 4311 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

Hi fellows I have a function that(suppose) creates a font and another to use it. Here it is:
unsigned int GenTextFont(const char * cFontName, HDC * windowHdc)
{
   HFONT theFont;
   unsigned int uiFont = glGenLists(255);
   if(uiFont == 0) return 0;
   theFont = CreateFont(20, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, FF_DONTCARE|DEFAULT_PITCH, cFontName);
   if(theFont == NULL){MessageBox(NULL, "Fonte nao criada","Erro",MB_OK|MB_ICONERROR); return 0;}
   wglUseFontBitmaps(*windowHdc, 32, 223, uiFont);
   SelectObject(*windowHdc, theFont);
   DeleteObject(theFont);
   return uiFont;
}

void PrintText(const char * cText, unsigned int uiFont)
{
   if(uiFont == 0)MessageBox(NULL, "", "", MB_OK);
   glPushAttrib(GL_LIST_BIT);
      glListBase(uiFont - 32);
	  glCallLists(strlen(cText), GL_UNSIGNED_BYTE, cText);
   glPopAttrib();
}

This code is correct, but my glGenLists always returns zero. I'm using these functions in my window loop:
while(!bQuit)
   {
      if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
	  {
         if(msg.message == WM_QUIT)
		 {
			bQuit =!bQuit;
	        break;             
		 }
         else
		 {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
		 }
	  }
	  else
	  {
	     GetClientRect(hwnd, &tempRect);
	     glMatrixMode(GL_PROJECTION);
	     glLoadIdentity();
	     gluOrtho2D(0,tempRect.right, tempRect.bottom, 0);
		 glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
		 SetFieldOfView(tempRect.right,tempRect.bottom);
		 glColor3f(1.0f, 1.0f, 1.0f);
	     glRasterPos3f(0,0,-0.1);
		 glColor3f(1.0, 1.0, 1.0);
		 PrintText("Texto", font);
...

What's the problem with my function? Thanks a lot.

Share this post


Link to post
Share on other sites
Advertisement
you're totally right, I'm calling my function that creates the bitmapfont BEFORE initialize my window for OpenGL


Thanks

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!