Quake & Outline Fonts
Hello, all!
Many of you may not know me, but for those that pay attention to the QER & QSG message boards, I''m Guy Paddock and I''m currently working on a 3D OS based on the Quake engine. So far, I think I''ve rewritten so much code that by time I''m done, nothing from the original Quake engine will be left! But that''s beside the point....
My main problem is that I''m a newbie to both C/C++ & OpenGL. I catch on to new languages pretty well, and I know what I''m doing when I''m coding in C/C++. It''s just the API I don''t know that well. That also includes OpenGL. I understand the basics of it, but I don''t understand complex things (complex to me, that is). Like, why does OpenGL have 3 matrices? This really does not hinder me much in my current project because almost everything I need is already implemented by the Quake engine in some manner. However, new features, like a new font system or AVI playback, are not. I want to implement Outline Fonts, from Lesson 14, in my code so that instead of using Quake''s original font system (bitmapped fonts), I can make fonts on-the-fly. I tried modifying the code to run inside a function, but the trouble is that it either didn''t work (in 2d screens, like the main menu) or made the entire world disappear, with the text at the screen center (in maps). What am I doing wrong? The engine already sets-up OpenGL to render scenes & 2d graphics, and by using the font routine, I don''t think it''s expecting to be in the mode the engine is in when it renders. Any ideas? All comments are helpful.
--Guy
You should post some code, or a link to your code. Far as I can tell, calling a display list to display fonts shouldn''t do that.... If you want, I can even send you some simple code I wrote involving outline fonts if you think it can help you.
-Blackstream Will you, won't you, will you, won't you, won't you take my virus?-The Mad HackerBlackstream's Webpage
/* Filename: gl_fonts.c */
extern HDC maindc; // Drawing context is created and handled by the Quake engine automatically during video initialization
GLYPHMETRICSFLOAT gmf[256];
GLuint base;
GLvoid Font_Build(GLvoid) {
HFONT font;
base = glGenLists(256);
font = CreateFont(-12, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, FF_DONTCARE|DEFAULT_PITCH, "Comic Sans MS");
SelectObject(maindc, font);
wglUseFontOutlines(maindc, 0, 255, base, 0.0f, 0.2f, WGL_FONT_POLYGONS, gmf);
}
GLvoid Font_Init(GLvoid) {
Font_Build();
}
GLvoid Font_Shutdown(GLvoid) {
glDeleteLists(base, 256);
}
GLvoid Font_Print(const char *fmt, ...)
{
float length = 0;
char text[256];
va_list ap;
unsigned int loop;
if (fmt == NULL)
return;
/*My custom code -- attempted to remedy the problem of the menu being rendered in a possibly different matrix
*/
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
// I don''t know if any of this is needed here....
// Some things may be handled by the engine itself automatically.
glShadeModel(GL_SMOOTH);
glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHTING);
glEnable(GL_COLOR_MATERIAL);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glTranslatef(0.0f,0.0f,-10.0f);
glColor3f(0.4f, 0.3f, 0.2f); // When enabled with GL_COLOR_MATERIAL, everything is red!
va_start(ap, fmt);
vsprintf(text, fmt, ap);
va_end(ap);
for (loop = 0; loop < (strlen(text)); loop++)
length += gmf[text[loop]].gmfCellIncX;
glTranslatef(-length/2,0.0f,0.0f);
glPushAttrib(GL_LIST_BIT);
glListBase(base);
glCallLists(strlen(text), GL_UNSIGNED_BYTE, text);
glPopAttrib();
/* Since I want to set things back to the way they were before I drew the text, I need to disable things I enabled. */
glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHT0);
glDisable(GL_LIGHTING);
glDisable(GL_COLOR_MATERIAL);
glPopMatrix();
}
Font_Init() is called during engine startup, Font_Shutdown() is called during engine shutdown (in Host_Init() and Host_Shutdown() respectively. Any ideas? I don''t know why this doesn''t work. Is it possible the menu is being drawn in the projection matrix?
extern HDC maindc; // Drawing context is created and handled by the Quake engine automatically during video initialization
GLYPHMETRICSFLOAT gmf[256];
GLuint base;
GLvoid Font_Build(GLvoid) {
HFONT font;
base = glGenLists(256);
font = CreateFont(-12, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, FF_DONTCARE|DEFAULT_PITCH, "Comic Sans MS");
SelectObject(maindc, font);
wglUseFontOutlines(maindc, 0, 255, base, 0.0f, 0.2f, WGL_FONT_POLYGONS, gmf);
}
GLvoid Font_Init(GLvoid) {
Font_Build();
}
GLvoid Font_Shutdown(GLvoid) {
glDeleteLists(base, 256);
}
GLvoid Font_Print(const char *fmt, ...)
{
float length = 0;
char text[256];
va_list ap;
unsigned int loop;
if (fmt == NULL)
return;
/*My custom code -- attempted to remedy the problem of the menu being rendered in a possibly different matrix
*/
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
// I don''t know if any of this is needed here....
// Some things may be handled by the engine itself automatically.
glShadeModel(GL_SMOOTH);
glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHTING);
glEnable(GL_COLOR_MATERIAL);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glTranslatef(0.0f,0.0f,-10.0f);
glColor3f(0.4f, 0.3f, 0.2f); // When enabled with GL_COLOR_MATERIAL, everything is red!
va_start(ap, fmt);
vsprintf(text, fmt, ap);
va_end(ap);
for (loop = 0; loop < (strlen(text)); loop++)
length += gmf[text[loop]].gmfCellIncX;
glTranslatef(-length/2,0.0f,0.0f);
glPushAttrib(GL_LIST_BIT);
glListBase(base);
glCallLists(strlen(text), GL_UNSIGNED_BYTE, text);
glPopAttrib();
/* Since I want to set things back to the way they were before I drew the text, I need to disable things I enabled. */
glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHT0);
glDisable(GL_LIGHTING);
glDisable(GL_COLOR_MATERIAL);
glPopMatrix();
}
Font_Init() is called during engine startup, Font_Shutdown() is called during engine shutdown (in Host_Init() and Host_Shutdown() respectively. Any ideas? I don''t know why this doesn''t work. Is it possible the menu is being drawn in the projection matrix?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement