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.