PDA

View Full Version : two questions concerning fonts and glClear



dfanuk
04-09-2002, 02:55 AM
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

mphanke
04-09-2002, 07:47 AM
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

mphanke
04-09-2002, 07:52 AM
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

zeckensack
04-09-2002, 01:19 PM
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 http://www.opengl.org/discussion_boards/ubb/confused.gif ), 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.

dfanuk
04-11-2002, 10:41 AM
Hurrah, I've got the fonts working. Thanks for your help on that one Martin

now to work on this glClear problem...

dfanuk
04-11-2002, 10:49 AM
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 http://www.opengl.org/discussion_boards/ubb/redface.gif
sorry for my newbie-ness!

please help!

Gareth
<><

J P
04-11-2002, 12:35 PM
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.

Michael Steinberg
04-12-2002, 12:28 AM
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.

dfanuk
04-12-2002, 01:44 AM
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
<><