Ady96 Ady96 - 3 years ago 285
C++ Question

Understanding glClearColor values

I am trying to create a single openGl window with some background color picked in RGB color picker but it looks like I am missing something important in this function. When I want to set color to standard, for example red color, it works.

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

But when I want to set some exotic color like
184, 213, 238, 1
then it shows only white.

glClearColor(184.0f, 213.0f, 238.0f, 1.0f);

What am I doing wrong? And what are the decimal values for and also the

Answer Source

See the Khronos documentation page for glClearColor, which clearly says:

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

glClearColor specifies the red, green, blue, and alpha values used by glClear to clear the color buffers. Values specified by glClearColor are clamped to the range [0,1].

This means the parameters are floating point values in the range from 0.0 to 1.0. Adapt your code like this:

glClearColor(184.0f/255.0f, 213.0f/255.0f, 238.0f/255.0f, 1.0f);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download