Bitmap Font Problem when using glut?

Started by
3 comments, last by ixion 19 years, 10 months ago
Hi I want to show some bitmapfont text in my opengl program, so i had a look at the NeHe Lesson 13. The downloadable code compiled and worked fine. I copy and pasted the relevant methods to my sourcecode, in which i am creating my window with glut. But there is no text shown at all. As far as i can see ist the only difference between my programm and the NeHe Code the way of creating the window. Just for testing purposes i wrote a simple new program with a glut window an the font methods, which doesn''t work, too. You can take a lot at the code here: http://www.uni-koblenz.de/~ansgar/OpenGL/main.cpp Any suggestions? If this doesn''t work out soon, i''ll try texture font instead.
Advertisement
Hi. I see a few things that you need to change:

--In a reshape function, you need to do the following:
a. Setup your viewport (you've done this)
b. Set the matrix mode to GL_PROJECTION to mess with the projection matrix stack and then clear it via glLoadIdentity() (). (you've done this)
c. Setup your projection (which you've done; ortho mode).
d. Set the matrix mode to GL_MODELVIEW so you can do your drawing.
e. Call glLoadIdentity() again to reset the MODELVIEW matrix.

You've done a-c, but not d-e. (Very important)


--Since your scene "has depth" [not just (x, y) or 2D, but 3D or (x, y, z)], you're going to want to add GL_DEPTH_BUFFER_BIT to the glClear call at the beginning of your display function:
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) ;

--You need to call glLoadIdentity() at the beginning in your display function so that your MODELVIEW matrix gets reset (loaded with the identity matrix) every time you draw a frame. (Very important)

~Urayami

[edited by - urayami on May 27, 2004 3:10:27 PM]
~Urayami
Hi urayami
You are right with what you wrote. But i still don''t get, why i can''t see any text displayed. The reshape function has no effect on what''s shown after executing the program. Correcting the other two mistakes i made, also didn''t bring the font to screen.
Do you have any other suggestons?
Of course everybody is welcome to try modifying my small testcode to get it work. :-)
I think I know what went wrong with my program: The following functions need to get the device context (hDC) to work.

wglUseFontBitmaps(hDC, 32, 96, base);
SelectObject(hDC, oldfont);

The problem is, that I don''t know how to get the device context of the glut windows i create. Any suggestions?
If you look at the NeHe Lesson 13 page and go to the bottom, there are a couple of conversions for this lesson to GLUT. However, I don''t think you will be able to do it directly, ie. you will have to come up with a workaround to get the font in there. It is because function with a wgl*** in front of it is a Windows specific extension to OpenGL. Since GLUT is cross platform, it would not have the facilities to interact with wgl*** code.


First make it work, then make it fast. --Brian Kernighan

The problems of this world cannot possibly be solved by skeptics or cynics whose horizons are limited by the obvious realities. We need men and women who can dream of things that never were. - John Fitzgerald Kennedy(35th US President)

Do not interrupt your enemy when he is making a mistake. - Napolean Bonaparte
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][LWJGL Tutorials for NeHe][LWJGL Wiki][jMonkey Engine]

This topic is closed to new replies.

Advertisement