two questions concerning fonts and glClear

Hi!

I am programming a project in C++ with OpenGL and have been using the nehe.gamedev.net tutorials as a basis for my code. I have been having a couple of difficulties and would appreciate help with them please!

Firsty, I have 4 buttons on my screen at the moment (these are basically 4 quads and I am detecting where the mouse is clicked). On clicking on the topmost 3 buttons the user should be taken to a new screen (a different screen for each one). However, I do not have a different screen I am going to totally change my current screen instead. At the moment I am trying to get the top button working. The main screen has a black background and the screen which the top button leads to has a white background. My problem is that when I click on this button when the program is running, nothing happens. I have a variable, called screen, which refers to which screen the user is on.
This is my DrawGLScene function:

int DrawGLScene(GLvoid) //Here’s Where We Do All The Drawing
{
switch (screen)
{
case 0:
{
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

… then some text and quad code

return 0;
}
case 1:
{
glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();

return 0;
}
}
return TRUE; //Everything Went OK
}

The idea being that at the moment I just want to check that it is clearing the screen when the mouse is clicked. I know that the mouse code is correct as I am able to exit the program by clicking on the bottom button.

My second problem is that I am unsure how to use more than one different font in my program. I used the NeHe font tutorial and can now easily put text on the screen with one font but am not sure how to change the fonts as it seems to link the font to the hDC.

If anyone can help with either or both of these problems I would be very grateful!

Thanks
Gareth

Hi,

if you are using the 3D-Font-Example, all you have to do is to setup a display list for each font. Then it should work fine. I will have a look at the 2D-Font stuff in a second, then I will post again.

Cheers,

Martin

Hi again,

from my point of view this should be solved with two display lists to. I’m out of office at the moment, but thursday I will be home, by then I will have a closer look at this. If you haven’t solved all this by then send me a mail.

Cheers,

Martin

Regarding problem 1:
You sure swap buffers after drawing? And you sure draw at least after every mouse event?
Add something like this to your DrawScene to help you track it down:

new global variables:
int screen0=0;
int screen1=0;

in drawing funtion:

switch(screen)
{
case(0):
++screen0;
//your stuff
case(1):
++screen1;
//your stuff
}

Then you can log screen0 and screen1 at shutdown and see how often you went through the rendering of screen 0 and screen 1 respectively. If both numbers are very small, you’re not continuously redrawing. If the sum of both is smaller than the amount of mouse events+ a few (maybe 1 ), you’re not redrawing after mouse events.
If you do sufficient redraws and screen1 is still zero even though you click on the right button, your mouse event handler is broken.

Hurrah, I’ve got the fonts working. Thanks for your help on that one Martin

now to work on this glClear problem…

zeckensack - thanks for your help, good idea. my current problem is that I don’t know how to look at the value of a variable after the program has ended
sorry for my newbie-ness!

please help!

Gareth
<><

Write the variable to a log file, say log.txt. Then inspect the log file for the value of the variable. As long as the file is closed before the program terminates, you are OK. I think that is what Zeckensack suggested.

Run the application in debug-mode and put a breakpoint at the end of the program. In my eyes that is the most comfortable way.

Thanks. I used JP’s log.txt idea and the value for screen0 was 315 and the value for screen1 was 0 even tho I did click on the case 1 button.
Thanks, now I know where the problem is, sort of!

Gareth
<><