Context & stateGL 1.0

glClearColor

Chooses the color glClear will fill the color buffer with.

Signature

void glClearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);

How it works

This only stores a color in the context state — it does not clear anything by itself. The next glClear(GL_COLOR_BUFFER_BIT) uses it. Since it is state, you can set it once at startup.

Parameters

redGLfloat

Red, 0.0 to 1.0.

greenGLfloat

Green, 0.0 to 1.0.

blueGLfloat

Blue, 0.0 to 1.0.

alphaGLfloat

Alpha, usually 1.0.

Tips & pitfalls

  • Values are floats between 0 and 1, not 0–255. Divide by 255 if you copy a color from a picker.

Example

example.cpp
1glClearColor(0.1f, 0.1f, 0.12f, 1.0f); // dark grey
2// every frame:
3glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
Official Khronos documentation