Jump to content
  • Advertisement
Sign in to follow this  
cutovoi

OpenGL The font doesn't draw

This topic is 4527 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'm trying to draw a font in OpenGL but I'm failing in this. I think that my code is perfect but it isn't. Fellows for the love of god, what I've forgot to put? The source is this:
   //...code that creates the window
   EnableOpenGL(hwnd, &hdc, &glrc);
   while(msg.message != WM_QUIT)
   {
      if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
      {
         TranslateMessage(&msg);
         DispatchMessage(&msg);
      }
      else
      {
         glMatrixMode(GL_PROJECTION);
         glLoadIdentity();
         gluOrtho2D(0, 800, 600, 0);
         //glClearColor(0.0f, 0.0f, 0.6f, 0.0f);
         glClear(GL_COLOR_BUFFER_BIT);
         glPushMatrix();         
         glColor3f(1.0f, 1.0f, 1.0f);
         glRasterPos2i(300, 400);
         PrintText(arialFont, "4");

         //myButton.Draw();
      }
      SwapBuffers(hdc);
   }
   DisableOpenGL(hwnd, hdc, glrc);
   return msg.wParam;
}

And this is my function that I create and draw the font
unsigned int CreateFont(HDC* hdc, char *fontName, int Size)
{
   HFONT hFont;
   unsigned int base = glGenLists(223);
   if(stricmp(fontName, "Arial")==0)
      hFont = CreateFont(Size, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE,SYMBOL_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, FF_DONTCARE | DEFAULT_PITCH, fontName);
   else 
      hFont = CreateFont(Size, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE,ANSI_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, FF_DONTCARE | DEFAULT_PITCH, fontName);
   if(!hFont)return 0;
   SelectObject(*hdc, hFont);
   wglUseFontBitmaps(*hdc, 32, 223, base);
   return base;
}

void PrintText(unsigned int base, char* string)
{
   if((base == 0 || string == NULL)) return;
   glPushAttrib(GL_LIST_BIT);  
      glListBase(base - 32);
      glCallLists(strlen(string), GL_UNSIGNED_BYTE, string);
   glPopAttrib(); 
}

Share this post


Link to post
Share on other sites
Advertisement
I want to draw the font. Now I discovered the error.
I'm calling the function that creates the font before the function that Enables OpenGL.

Thanx for the support

Share this post


Link to post
Share on other sites
There are two (possible) problems I noticed from the code you posted.

1) Are you calling your CreateFont function before or after you create the OpenGL context? All OpenGL calls are ignored if there isn't a current context.

2) You are pushing the projection matrix without later popping it. It doesn't seem like you are checking for OpenGL errors (you should be) because this would create one.

And as Ezbez succinctly put, the more information you give us the easier it will be to help you.

EDIT: Nevermind, I'm too slow.

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!