PDA

View Full Version : WglFontDemo



05-07-2005, 08:09 AM
What is going on here? WglFontDemo creates a font of height size 12,
but it doesn't appear on the screen as 12 pixels high. You can see
that the demo is arbitrarily scaling the font up (30,30,30).

And this line doesn't appear to be doing anything helpful:
glScaled( aspect, aspect, 1.0 );

How can I get an outlined font of height 12 on the screen?


glMatrixMode(GL_PROJECTION);
glLoadIdentity();

GLdouble size = (GLdouble)((w >= h) ? w : h) / 2.0;
GLdouble aspect;

if (w <= h) {
aspect = (GLdouble)h/(GLdouble)w;
glOrtho(-size, size, -size*aspect, size*aspect, -1000000.0, 1000000.0);
}
else {
aspect = (GLdouble)w/(GLdouble)h;
glOrtho(-size*aspect, size*aspect, -size, size, -1000000.0, 1000000.0);
}

/* Make the world and window coordinates coincide so that 1.0 in */
/* model space equals one pixel in window space. */
glScaled(aspect, aspect, 1.0); // NO WORK?

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

if (m_olf) {
glColor3f(1.0, 5.0, 1.0);
glPushMatrix(); {
glRotatef(45.0, 0.0, 0.0, 1.0);
glTranslatef(-150.0, 100.0, 0.0);
glScalef(30.0, 30.0, 30.0); // WTF??
m_olf->DrawString("This is an outline font.");
} glPopMatrix();
}

CWiC
05-08-2005, 02:21 AM
I think it's good idea to post link to example if you talking about it, not all here can read smb.'s mind ;)
http://www.opengl.org/resources/features/fontsurvey/sooft/examples/WglFontDemo.zip
Regarding your question, if you want to see some effect of that glScaled( aspect, aspect, 1.0 ); line just change it to glScaled( aspect/2, aspect/3, 1.0 ); and you'll see that it does affect the scene appearence.
If you read the help to LOGFONT->lfHeight entry in MSDN you can see that it: "Specifies the height, in logical units, of the font's character cell or character." the keywords here are logical units so you can't expect that it will much to pixels. Use scaling (your //WTF comment) to set desired font size. I can't provide a formula for calculating correct scale to get desired size in pixels but you always can try and see which scale factor is good for your particular needs.

05-08-2005, 05:08 AM
Thanks, yes, I would like to know how to get a font created with wglUseFontOutlines() to
render 12 pixels high.

Since wglUseFontBitmaps() created a 12 pixel high font, I expected wglUseFontOutlines()
to do the same, but it apparently gives me something entirely different. I can't even use
glRasterPos() to precisely position my outlined font on the screen.

05-08-2005, 07:16 AM
Have you ever used the info returned from the GLYPHMETRICSFLOAT struct?

This might work to get a 12-pixel high font:

float scale = 12.0f / gmf[i].gmfBlackBoxY;
glScalef( scale, scale, scale );


BlackBox GlyphOrigin CellInc
[ 48] char: 0 ( 0.417480,0.653809) (0.037109,0.643066) (0.497559,0.000000)

[ 49] char: 1 ( 0.235840,0.643066) (0.097168,0.643066) (0.497559,0.000000)

[ 50] char: 2 ( 0.424316,0.643066) (0.025879,0.643066) (0.497559,0.000000)

[ 51] char: 3 ( 0.419434,0.653809) (0.037598,0.643066) (0.497559,0.000000)

[ 52] char: 4 ( 0.442871,0.640625) (0.011230,0.640625) (0.497559,0.000000)

[ 53] char: 5 ( 0.424805,0.643066) (0.037109,0.632324) (0.497559,0.000000)

[ 54] char: 6 ( 0.423340,0.653809) (0.033691,0.643066) (0.497559,0.000000)

[ 55] char: 7 ( 0.414551,0.632324) (0.042480,0.632324) (0.497559,0.000000)

[ 56] char: 8 ( 0.421875,0.653809) (0.036133,0.643066) (0.497559,0.000000)

[ 57] char: 9 ( 0.420898,0.653809) (0.037109,0.643066) (0.497559,0.000000)Although, I have no idea what 'notional units' are and how they related to pixels.

05-08-2005, 08:20 AM
I created three 3 outlined fonts, of sizes 12, 24 and 48, all of type "Arial":

fh = -MulDiv( 12, GetDeviceCaps( dc->GetSafeHdc(), LOGPIXELSY), 72 );
fh = -MulDiv( 24, GetDeviceCaps( dc->GetSafeHdc(), LOGPIXELSY), 72 );
fh = -MulDiv( 48, GetDeviceCaps( dc->GetSafeHdc(), LOGPIXELSY), 72 );

LOGFONT logfont;
logfont.lfHeight = fh;

And I get the same GLYPHMETRICSFLOAT numbers for all of them?

What's the point of setting lfHeight when it doesn't seem to matter?
The quality of the font looks the same for all of them.

05-08-2005, 08:34 AM
I just read somewhere that wglUseFontOutlines() ignores the LOGFONT lfHeight parameter,
therefore I must use glScalef() if I want to get it to a certain pixel height.