I tried to display texture mapped fonts. I read at the NeHe site, that I shouldn’t use Ortho, because it is ugly. In my case, I have to use it. And it’s faster to set the screen coordinates.
I used the code below:
This code works perfectly, but if I enable the glOrtho and the rasterpos lines, I don’t get anything written on the screen.
What is wrong here??? Pls help
glMatrixMode(GL_MODELVIEW);
glPushMatrix(); // GL_MODELVIEW
glLoadIdentity();
glMatrixMode(GL_PROJECTION);
glPushMatrix(); // GL_PROJECTION
glLoadIdentity();
gluOrtho2D(0.0, 800.0, 600.0, 0.0);
glPushAttrib(GL_LIST_BIT | GL_LIGHTING_BIT);
glDisable(GL_LIGHTING);
glListBase(base);
glColor3f(1.0, 1.0, 1.0); // Your font color when using bitmaps.
glRasterPos2i(50, 50);
glCallLists(6, GL_UNSIGNED_BYTE, "Hello.");
glPopAttrib(); // list base and lighting state restored
glPopMatrix(); // GL_PROJECTION
glMatrixMode(GL_MODELVIEW);
glPopMatrix(); // GL_MODELVIEW
SwapBuffers(DCvalue);
The code above should work nicely with wglUseFontBitmaps. With a do-it-yourself texture font, what did you compile into the display lists which works with glRasterPos? (Means, it’s not useful for a font texture.)
If you use textured quads per letter, switch the GL_MODELVIEW to be inside in my code, so that possible glTranslate calls you have per letter affect that right matrix.
If this doesn’t help, set your glClearColor to a weird color.
Check your font texture environment (e.g. GL_REPLACE instead of GL_MODULATE).
Strange. I don’t see anything…
Maybe the error is in the previous lines? I pasted your code directly into mine, overwriting everything.
Here’s what comes before your code:
Does it work without the texture?
Wait, you said that code worked before, so what was your matrix setup then?
Maybe it’s so tiny that there is only a single point.
With wglUseFontOutlines you should probably move the modelview inside like this, as I don’t know how the display lists advance the position depending on the glyph widths:
glMatrixMode(GL_PROJECTION);
glPushMatrix(); // GL_PROJECTION
glLoadIdentity();
gluOrtho2D(0.0, 800.0, 0.0, 600.0); // Let's order it the OpenGL way for debugging.
glMatrixMode(GL_MODELVIEW);
glPushMatrix();// GL_MODELVIEW
glLoadIdentity();
glPushAttrib(GL_LIST_BIT | GL_LIGHTING_BIT);
glDisable(GL_LIGHTING);
glListBase(base);
glColor3f(1.0, 1.0, 1.0); // Your font color when using bitmaps.
glRasterPos2i(50, 50);
glCallLists(6, GL_UNSIGNED_BYTE, "Hello.");
glPopAttrib(); // list base and lighting state restored
glMatrixMode(GL_PROJECTION);
glPopMatrix(); // GL_PROJECTION
glMatrixMode(GL_MODELVIEW);
glPopMatrix(); // GL_MODELVIEW
SwapBuffers(DCvalue);
If this gets you a tiny point in the bottom left corner, try gluOrtho2D(0.0, 8.0, 0.0, 6.0);
Bigger now?
The whole code works OK when I remove the glOrtho line. The letters appear at position 0,0. This is normal.
If I leave Ortho, I see a black screen.
The bitmap i use is a 512x512 bmp. It is loaded correctly, as the result is fine (without Ortho).
I think i will use another way to display the text: 0,0 is the center of the screen(400,300). -1,-1 will be 0,0, etc. Maybe. A bit lame thing when you can have ortho…
Thank you for the help. If you want, you can continue trying, but I don’t want to ask more of your time.
This thing remains a mistery to me. I used Ortho many times and it only failed once: with fonts…