PDA

View Full Version : glClear() not clearing



gusto52
10-15-2003, 09:01 AM
HI-
I'm having a problem with glClear(), mainly that it doesn't clear. I'm using quadrics to make a model that I then convert to another format for viewing using glReadPixels(). The model appears in the alternate format alright, but with the default background and pieces missing. The missing pieces usually correspond to areas of the buffer that contained non-background pixels in previous runs of the program. I've made the same model in a seperate program that displays the buffer directly by using SwapBuffers(hDC), and this works fine. However, if I remove glClear() from that program I get the same effect that I got with the first program. I've tried everything I can think of - clearing other buffers, drawing the scene to other buggers, placing the call to glClear in different places, etc -and nothing can clear the scene that I'm reading.
Any suggestions at all will be appreciated, and thanks in advance for your help!
-gusto

Tenson
10-15-2003, 12:21 PM
Are the following lines in your code?

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

gusto52
10-23-2003, 06:19 AM
Yes. I've tried that code and every variation on it I can find. Even placing the clear directly after declaring/defing the objects in the scene (with gluDisk, etc) has no effect (it should clear everything, but instead the partially drawn object is still there).
(thanks for the reply though)

Deiussum
10-23-2003, 06:34 AM
Are you using double buffering? If so, do you swap the buffers after the clear? Do you draw something else immediately afterwards? Do you have a scissor region defined? Any write masks set to false?

Edit: Some code of your display function would definitely be useful here to see what you are doing wrong.

[This message has been edited by Deiussum (edited 10-23-2003).]

gusto52
10-23-2003, 07:15 AM
I'm using double buffering, but I'm reading the pixel values from the Color Buffer using glReadPixels, so if makes no difference if I swap the buffers or not. I've tried using single buffering, but I have been unable to make my model appear at all - rather it shows a portion of the screen from another porgram. I'm not using a scissor region, and I don't know what a write mask is.
Like I said, I made a second version of the program that uses the same openGL code, except that it draws it using SwapBuffers instead of ReadPixels.

Deiussum
10-23-2003, 07:57 AM
You sound confused.

"I made a second version of the program that uses the same openGL code, except that it draws it using SwapBuffers instead of ReadPixels."

Neither SwapBuffers nor ReadPixels draw anything. ReadPixels will read stuff that has already been drawn to the buffers, it doesn't draw anything. SwapBuffers simply brings the back buffer to the front so that it is visible.

I'm also confused by what you mean here...

"I'm using double buffering, but I'm reading the pixel values from the Color Buffer using glReadPixels, so if makes no difference if I swap the buffers or not."

Reading values from the color buffer with glReadPixels is NOT the same thing as swapping the buffers, so it DOES make a difference.

Again, post some code so we can see what exactly you are doing wrong.

Jan
10-23-2003, 08:50 AM
Put a glColorMask (GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE) and a glDepthMask (GL_TRUE) before the line where you clear the buffer.

Color and depth masks do affect wich components get cleared.

Jan.