glClear question
Hello
In my program I start off with a menu screen with a black background. There are 4 buttons. What I am trying to do is, when the user clicks one of the buttons the screen is cleared, the background becomes white and it''ll be as if the user has progressed to a new screen. Is it wise to try and do it all with one window? I think it should work. In my DrawGLScene function I have a switch statement which checks an integer variable called screen to see which screen the user is on. I want the background to be different colours for each screen so I have put in a glClearColor line at the top of each case statement. actually here''s the code
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);
.....
.....
some quad statements, etc
}
case 1:
{
glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
....
....
}
etc
When I run the program, though screen equals 0, I get a white background.
I must be missing something, can anyone help please?
Thanks
Gareth
<><
have you got a break after each case in your switch statement? if not, it will just drop through and clear the screen white (as you are experiencing)
ah right, thanks. ok I''ve now added
return 0;
to the bottom of each statement and the program loads properly. Now, though, when I press the top button, which sets screen equal to 1, nothing happens except the screen seems to freeze, i.e it doesnt clear the screen and leave just a white background. But the exit button still works even though it''s not even meant to be there!
hmm I''m confused
Gareth
<><
return 0;
to the bottom of each statement and the program loads properly. Now, though, when I press the top button, which sets screen equal to 1, nothing happens except the screen seems to freeze, i.e it doesnt clear the screen and leave just a white background. But the exit button still works even though it''s not even meant to be there!
hmm I''m confused
Gareth
<><
I''ve put swapbuffers(hDC) in the WinMain function and it gets called if the program is active and Escape isnt being pressed.
I have got glEnable(GL_DEPTH_TEST) in my InitGL function
I have got glEnable(GL_DEPTH_TEST) in my InitGL function
April 06, 2002 07:43 AM
1) You need to swapbuffers()every time you want to repaint the bacground with a different color.
2) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) doesn''t need be in your logic (switch section) Just call it before the swapbuffers.
I have a MFC dialogbox app that switches the background color depending on rgb values that you type in. Even if you don''t want MFC, it could help you and I can email it to you if you want to look at it.
2) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) doesn''t need be in your logic (switch section) Just call it before the swapbuffers.
I have a MFC dialogbox app that switches the background color depending on rgb values that you type in. Even if you don''t want MFC, it could help you and I can email it to you if you want to look at it.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement