Hi, I've been trying to implement outline fonts in my project lately, and as far as I can tell, theyre not being drawn at all. I think it has something to do with glOrtho(), but thats a bit of a stab in the dark. I have also ensured every glPopMatrix() is matched with a glPushMatrix().
Due to the size of my project, it makes no sense for me to post all my code. But, I will try and show everything relevent. If there is anything else you need to see, just ask.
The text is stored in these variables:
GLuint Font;
GLYPHMETRICSFLOAT GMFBuffer[256];
And is rendered like this:
GLEnable2D(1280, 1024);
glDisable(GL_TEXTURE_2D);// disable Texture Mapping
glPushMatrix();
glLoadIdentity();
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glTranslatef(50.0f, 50.0f, 0);
GLPrintStringOL(Target.Font, "neeber");
glPopMatrix();
glEnable(GL_TEXTURE_2D);// Enable Texture Mapping
GLDisable2D();
The text is created using this function:
//*************************************************************************************//
//********************************CREATE AN OUTLINE FONT*******************************//
//*************************************************************************************//
unsigned int CreateOutlineFont(char *fontName, int fontSize, float Extrusion, int Format, GLYPHMETRICSFLOAT *GMFBuffer, HDC hDevCon)
{
HFONT hFont; // windows font
unsigned int base;
base = glGenLists(256); // create storage for 96 characters
if (stricmp(fontName, "symbol") == 0)
{
hFont = CreateFont(fontSize, 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(fontSize, 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(hDevCon, hFont);
wglUseFontOutlines(hDevCon, 0, 255, base, 0.0f, Extrusion, Format, GMFBuffer);
return base;
}
Like this:
Font = CreateOutlineFont("Console", 150, 0.0f, WGL_FONT_POLYGONS, GMFBuffer, hDevCon);
The text is drawn using this function:
//*************************************************************************************//
//*******************************PRINT AN OUTLINE FONT*********************************//
//*************************************************************************************//
void GLPrintStringOL(unsigned int Base, char *str)
{
if(str == NULL)
return;
//draw the text
glPushAttrib(GL_LIST_BIT);
glListBase(Base);
glCallLists(strlen(str), GL_UNSIGNED_BYTE, str);
glPopAttrib();
}
The following flags are enabled when OpenGL is initialised:
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_TEXTURE_2D);
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_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_COLOR_MATERIAL);
The 2D perspective functions look like this:
//*************************************************************************************//
//******************************ENABLE 2D DRAWING MODE*********************************//
//*************************************************************************************//
void GLEnable2D(long ScreenResX, long ScreenRezY)
{
int vPort[4];//space for the viewport data
glGetIntegerv(GL_VIEWPORT, vPort);//get the viewport data
glMatrixMode(GL_PROJECTION);//set the matrix mode
glPushMatrix();//push the matrix onto the stack
glLoadIdentity();//load the default identity
glOrtho(0, ScreenResX, ScreenRezY, 0, -10, 10);//set our frindly little fella to ortho
glMatrixMode(GL_MODELVIEW);//set the matrix mode
glPushMatrix();//push the matrix onto the stack
glLoadIdentity();//now load the default
}
//*************************************************************************************//
//*****************************DISABLE 2D DRAWING MODE*********************************//
//*************************************************************************************//
void GLDisable2D()
{
glMatrixMode(GL_PROJECTION);//set the matrix mode
glPopMatrix(); //pop it back to last position, i love this function
glMatrixMode(GL_MODELVIEW);//set the matrix mode again
glPopMatrix();//now pop it again
// no need to return a value
}