PDA

View Full Version : Can you use Outline font in 2d environment?



skyeyes
05-18-2008, 01:52 PM
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

Zengar
05-18-2008, 03:22 PM
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.

Relic
05-19-2008, 01:42 AM
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. :p
Try with a smaller glOrtho setup or add a glScale to the font rendering.

skyeyes
05-19-2008, 03:10 AM
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

Zengar
05-19-2008, 04:41 AM
Just do what Relic says...

skyeyes
05-19-2008, 06:23 AM
Zengar, my above code has got the glScalef as pointed out by relic but it still is not working.

Relic
05-19-2008, 06:30 AM
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. :D

Zengar
05-19-2008, 07:16 AM
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.

-NiCo-
05-19-2008, 07:37 AM
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.

Relic
05-19-2008, 09:33 AM
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);
...

skyeyes
05-19-2008, 09:48 AM
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

Relic
05-19-2008, 10:30 AM
Too easy! :D
You're welcome!