0
votes

Well, I recently looked in the OpenGL docs, and I realized that glClear(GL_COLOR_BUFFER_BIT) clears the color buffer using a color set by glClearColor. According to theCodingUniverse on YouTube, glClearColor should be called before glClear. Is this correct? I don't think it is, but why does it still work then? Will clearing the buffer and then setting the color produce any bad results?

1
You don't have to call glClearColor (...). Like everything in OpenGL, the clear color has a default value (0, 0, 0, 0) in this case. Also, like everything else in OpenGL you only have to set the value once and it will remember it for you. Unrelated, but when did YouTube become a legitimate source of information? :P - Andon M. Coleman
Well yes, but generally speaking if I want to clear the buffer to a certain color, should I set the color before clearing it? That's my question. - user1650305
Yes, you need to set the clear color before executing glClear (...). - Andon M. Coleman

1 Answers

1
votes

No difference really. If you set the clear color after you clear the color buffer then opengl remembers it and the next time the buffer is cleared (the next frame) it will be cleared to that color. So the first frame will have a different clear color, which doesn't really matter.

Although for the sake of practice I would put it before.