using text
Is there a function sort of like cout<< to put text in a Open GL application? If yes, what is the code nessesery and how do I use it? Thanks
No, you have to write your own. Text output is too highlevel for a graphics API. But, luckily, it''s a lot easier than it sounds to do. There''s a NeHe tutorial on using textured fonts. His method is somewhat rudimentary, but it is easy to use as a starting point.
[Resist Windows XP''s Invasive Production Activation Technology!]
[Resist Windows XP''s Invasive Production Activation Technology!]
i had the same question a couple days ago. Nehe has some great font tutorials. Even if you dont have a clue how they work you can just copy the code into your own program without much trouble at all.
Use this code (by Nehe)
void BuildFont(void) {
HFONT font;
base = glGenLists(96);
font = CreateFont(-22,
0,
0,
0,
FW_BOLD,
FALSE,
FALSE,
FALSE,
ANSI_CHARSET,
OUT_TT_PRECIS,
CLIP_DEFAULT_PRECIS,
ANTIALIASED_QUALITY,
FF_DONTCARE | DEFAULT_PITCH,
"Times New Roman");
app_t window;
SelectObject(window.app->hDC, font);
wglUseFontBitmaps(window.app->hDC, 32, 96, base);
}
void DeleteFont(void) {
glDeleteLists(base, 96);
}
void PrintText(char *msg, ...) {
char text[256];
va_list argptr;
if (!msg)
return;
va_start(argptr, msg);
vsprintf(text, msg, argptr);
va_end(argptr);
glPushAttrib(GL_LIST_BIT);
glListBase(base - 32);
glCallLists(strlen(text), GL_UNSIGNED_BYTE, text);
glPopAttrib();
}
void BuildFont(void) {
HFONT font;
base = glGenLists(96);
font = CreateFont(-22,
0,
0,
0,
FW_BOLD,
FALSE,
FALSE,
FALSE,
ANSI_CHARSET,
OUT_TT_PRECIS,
CLIP_DEFAULT_PRECIS,
ANTIALIASED_QUALITY,
FF_DONTCARE | DEFAULT_PITCH,
"Times New Roman");
app_t window;
SelectObject(window.app->hDC, font);
wglUseFontBitmaps(window.app->hDC, 32, 96, base);
}
void DeleteFont(void) {
glDeleteLists(base, 96);
}
void PrintText(char *msg, ...) {
char text[256];
va_list argptr;
if (!msg)
return;
va_start(argptr, msg);
vsprintf(text, msg, argptr);
va_end(argptr);
glPushAttrib(GL_LIST_BIT);
glListBase(base - 32);
glCallLists(strlen(text), GL_UNSIGNED_BYTE, text);
glPopAttrib();
}
if you create a font class, you can define the << operator for it and render the text like that.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement