Original Post
Hi I'm currently using the windows implementation provided by the folk at nehe in my little shooter game. At the moment i'm trying to create a font class which for defining a new font then being able to print text with the font. The problem is I need access to my Device Context handle but that's in a different file. I've got a few source files windows.cpp which holds all the windows code (the hDC) and i've created a font class in not surprisingly font.h and .cpp. I tried taking the variables from the top of the windows.cpp file and putting them into a windows.h file but that seems to screw everthing up. One of my mates mentioned that I might be able to do something with externs to make the hDC a totally global variable or something but I haven't got the first clue about that. Cheers for advice and help. Neil [Edited by - bapti on December 4, 2005 11:40:49 AM]
THE FONT
unsigned int Font::Create_Font(char *fontName, int fontSize)
{
// Windows font.
HFONT hFont;
unsigned int base;
// Create space for 96 characters.
base = glGenLists(96);
if(stricmp(fontName, "symbol")==0)
{
hFont = CreateFont( -24,
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( -24,
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, 96, base);
return base;
}
AND THE BIT OF WINDOWS CODE FROM THE TOP OF WINDOWS.CPP
HDC hDC =NULL; // Private GDI Device Context
HGLRC hRC =NULL; // Permanent Rendering Context
HWND hWnd =NULL; // Holds Our Window Handle
HINSTANCE hInstance; // Holds The Instance Of The Application