Sign in to follow this  
Kustaz

OpenGL Outline fonts not drawing

Recommended Posts

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
}


Share this post


Link to post
Share on other sites
Check for errors in CreateOutlineFont, some function could simply fail there.
You could also disable GL_LIGHTING and try that with simply color.

My guess would be that it is because of the size of the glyphs you create. I didn't get it completely, but I still think it depends on the size of your viewport/projection.

Try:
1) Scale the font before drawing (enlarge / shrink)
2) Scale the viewport (it's ortho, try -1,1,-1,0 or 0,1,0,1) and then again scale the font.

Other than that, update your drivers :P

Share this post


Link to post
Share on other sites
hey!I'm a new , and I'm not sure this will help or not.
well ,I got some code several days ago.I'm glad to show them :) here:


void OpenGLFont::showText3D(HFONT hFont, const char* str, float z)
{
if(strlen(str) >=MAX_OPENGL_FONT_NUM) return;

unsigned char* pChar =new unsigned char[MAX_OPENGL_FONT_NUM];
HDC hdc = wglGetCurrentDC();
HFONT hOldFont = (HFONT)SelectObject(hdc, hFont);
strcpy((char*)pChar, str);

int n,len = strlen(str);
unsigned long dwChar = 0;
GLYPHMETRICSFLOAT pgmf[1];

pushStatus();
glPushMatrix();
for(int i = 0; i < len; i++)
{
if(IsDBCSLeadByte((unsigned char)pChar[i]))
{
dwChar = (unsigned long)pChar[i];
dwChar = dwChar<<8;
dwChar = dwChar | pChar[i+1];
i++;
}
else
dwChar = pChar[i];
n = glGenLists(1);
wglUseFontOutlines(
hdc,
dwChar,
1,
n,
0.0f,
z,
WGL_FONT_POLYGONS,
pgmf);
glCallList(n);
glDeleteLists(n , 1);
}
glPopMatrix();
popStatus();

delete pChar;
SelectObject(hdc, hOldFont);
}


And they worked well,and of course as you've seen ,you can draw 3D font(no matter ASCII and UNICODE).

Share this post


Link to post
Share on other sites
Paydirt! Thank you, I have found that it is due to my glOrtho() projection, and it is drawing it, just realy realy small in the corner. I scaled it, and it looks fine. Thank you!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this