Can you use Outline font in 2d environment?

Hi,

I’m having a hard time using my outline font code in a 2d environment. I’ve used glOrtho(-8.0f,width,height,-30.0f,-1.0f,1.0f);

However, after I’ve initialize the list, and I call
RenderFont(50.0f, 50.0f, 0.0f, m_fontListBase, “OpenGL Rocks!”); nothing is being displayed.

So, can somebody please confirmed for me if it is possible to use Outline font in a 2d environment in Opengl?

Thanks,
Sky

Of course it is possible, there is no real difference between 2d and 3d (it is all 3d anyway) other then a different projection matrix. Probably your coordinates are bad, so that the text appears somewhere outside the visible area.

The vertex data of the font’s glyphs are scaled to lie in the [0.0, 1.0] range!
If you have an ortho setup with window coordinates and your start point (50, 50) is onscreen, the font will be displayed really small. :stuck_out_tongue:
Try with a smaller glOrtho setup or add a glScale to the font rendering.

But, I’m having a hard time using my outline font code in a 2d environment.
My ResizeGLScene is:
GLvoid ReSizeGLScene(GLsizei width, GLsizei height)
{
if(height == 0)
{
height = 1;
}
glViewport(0,0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0f,width,height,0.0f,-100.0f,100.0f); // Create Ortho 640x480 View (0,0 At Top Left)
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

My InitGL function has a call to:
m_fontListBase = CreateOutlineFont(“Verdana”, 48, 0.2f);

My DrawGlScreen has a statement:
glPushMatrix();
glScalef(2.0f, 2.0f, 2.0f);
RenderFont(200.0, 200.0, 0.0, m_fontListBase, “OpenGL Outline Fonts!”);
glPopMatrix();

But only a tiny little dot is being displayed at 200,200. I’ve added/subtracted from the Z value and nothing is happining.

Can somebody please help or show me a sample code that uses glOrtho and Outline font together

Just do what Relic says…

Zengar, my above code has got the glScalef as pointed out by relic but it still is not working.

Maybe because it’s too small or it belongs inside your RenderFont() routine?
Can’t tell because we neither know the matrix state at the time you call glScalef() nor what the RenderFont() routine actually does. :smiley:

Well, from what relic said every character will be about one pixel large. If you enlarge it twice (with your glScale) it will still be about two pixels. No wonder you see only dots. Try another scaling.

I don’t know what’s inside the RenderFont() routine but if you’re scaling outside this function it’s possible that the initial raster position gets scaled as well so that it ends up outside your viewport.

Can somebody please help or show me a sample code that uses glOrtho and Outline font together

With your wglUseFontOutlines display lists already constructed try something like this instead of your RenderFont() routine (without the glScalef()):

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
// effectively a unit cube ortho setup
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glListBase(m_fontListBase);
glCallLists(1, GL_UNSIGNED_BYTE, “A”);

That should render a big “A” into the upper right quadrant of the viewport, because the origin is in the center of the screen and the glyph data is in the range [0, 1].

Now add glOrtho calls like this to see how that affects the renderings size (smaller since the projected area got bigger):
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-2.0, 2.0, -2.0, 2.0, 1, -1);

I’ve got it to work! Many thanks you all. You guys were right, all I needed to do was to scale it up with:
glScalef (100.0f, 100.0f, 100.0f);

Many thanks,
Jr

Too easy! :smiley:
You’re welcome!