When doing 2D OpenGL rendering and showing text (via wglUseFontOutlines and then calling the display lists), I can use the glScale to control the text size. My question is, what value of glScale should I use to get text rendered at a particular point size? i.e., I have a 14pt font rendered using GDI. I want to get the same result using 2D OpenGL rendering instead.
So I want to pick some scaling value which results in it rendering the same size as if I was doing GDI rendering using the 14pt font. Details are below.
I’m using Windows XP with Visual Studio 2005 and C++ developing a native Windows app.
I’m doing some OpenGL 2D rendering on top of the 3D rendered scene. So after doing the 3D rendering but before calling SwapBuffers, I set things up for 2D rendering so that the coordinate system lines up with the screen and the units are in pixels using the below code (pCanvasRect is set via GetClientRect in my window).
LONG rWidth = abs(pCanvasRect->right - pCanvasRect->left);
LONG rHeight = abs(pCanvasRect->bottom - pCanvasRect->top);
glDisable(GL_LIGHTING);
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
glViewport(pCanvasRect->left,pCanvasRect->top,rWidth,rHeight);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0,rWidth-1,rHeight-1,0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
The result of the above is that I can use the same coordinate system I would normally use with GDI rendering. Origin is at the top left, positive X to the right and positive Y down. And I can render a 2D box in OpenGL which is 100 units wide and it renders 100 pixels wide on the screen. One note is that I have to use a negative Y scale for drawing the text so it renders it right-side up (due to the Y axis reversal).
Anyway, if I’m trying to render text which looks identical to 14pt GDI rendering using the same font how do I figure out the correct scaling?
The examples I’ve dug through on the net all seem to just apply arbitrary scaling, probably as a result of trial and error, however I’d like to pick the correct scaling to match a point size font.
Any ideas?