Okay... here's what I've done, it's probably a very simple problem but right now I can't wrap my head around it.
I have the main.cpp file of a program Ive made as just the same as nehe's lesson 1 codebase.
But I've put the font classes (lesson 13) in a seperate file called font.cpp and font.h.
In font.h I declared the necessary functions..
GLvoid BuildFont(GLvoid);
GLvoid KillFont(GLvoid);
GLvoid glPrint(const char *fmt, ...);
And then I defined the full functions in font.cpp
GLuint base; // Base Display List For The Font Set
GLvoid BuildFont(GLvoid) // Build Our Bitmap Font
{
HFONT font; // Windows Font ID
HFONT oldfont; // Used For Good House Keeping
base = glGenLists(96); // Storage For 96 Characters ( NEW )
font = CreateFont( -24, // Height Of Font ( NEW )
0, // Width Of Font
0, // Angle Of Escapement
0, // Orientation Angle
FW_BOLD, // Font Weight
FALSE, // Italic
FALSE, // Underline
FALSE, // Strikeout
ANSI_CHARSET, // Character Set Identifier
OUT_TT_PRECIS, // Output Precision
CLIP_DEFAULT_PRECIS, // Clipping Precision
ANTIALIASED_QUALITY, // Output Quality
FF_DONTCARE|DEFAULT_PITCH, // Family And Pitch
"Courier New"); // Font Name
oldfont = (HFONT)SelectObject(hDC, font); // Selects The Font We Want
wglUseFontBitmaps(hDC, 32, 96, base); // Builds 96 Characters Starting At Character 32
SelectObject(hDC, oldfont); // Selects The Font We Want
DeleteObject(font); // Delete The Font
}
GLvoid KillFont(GLvoid) // Delete The Font List
{
glDeleteLists(base, 96); // Delete All 96 Characters ( NEW )
}
GLvoid glPrint(const char *fmt, ...) // Custom GL "Print" Routine
{
char text[256]; // Holds Our String
va_list ap; // Pointer To List Of Arguments
if (fmt == NULL) // If There's No Text
return; // Do Nothing
va_start(ap, fmt); // Parses The String For Variables
vsprintf(text, fmt, ap); // And Converts Symbols To Actual Numbers
va_end(ap); // Results Are Stored In Text
glPushAttrib(GL_LIST_BIT); // Pushes The Display List Bits ( NEW )
glListBase(base - 32); // Sets The Base Character to 32 ( NEW )
glCallLists(strlen(text), GL_UNSIGNED_BYTE, text); // Draws The Display List Text ( NEW )
glPopAttrib(); // Pops The Display List Bits ( NEW )
}
I've linked in all the necessary libs and headers e.t.c (not shown above).
Thing is.... u'll notice that the above code in font.cpp calls to HDC in the buildfont function... this generates an error in the compiler that looks like this.
"error C2065: 'hDC' : undeclared identifier"
HOWEVER.... if I define it here too, I get multiple hdc errors (already defined e.t.c e.t.c).
Any chance someone can help me out with this. I just need to be able to use HDC in main.cpp (for rendering the window) and in font.cpp (for building the font).
All help hugely appreciated... and sorry for the large code pastes above, but I felt posting everything was the best idea.
(and before anyone says "are you spelling it with right capitals e.t.c..." yes I am
just to clear up that).
Thanks in advance...
~Cobra~
Edited by - Cobra on February 4, 2002 3:42:06 PM
Edited by - Cobra on February 4, 2002 3:43:33 PM
"Build a man a fire, and he will be warm for a day. Set a man on fire, and he will have warmth for the rest of his life"