The Qt OpenGL Window Example shows a colored triangle. The colors, RGB corners, are set with:
static const GLfloat colors[] = {
1.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 1.0f
};
How do I change the black background to another color?
CodePudding user response:
You set the clear color with use of glClearColor function:
C Specification
void glClearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);Parameters
red,green,blue,alphaSpecify the red, green, blue, and alpha values used when the color buffers are cleared. The initial values are all
0.Description
glClearColorspecifies the red, green, blue, and alpha values used by [glClear][2]to clear the color buffers. Values specified byglClearColorare clamped to the range[0,1].
As documentation suggests, the clear color is used when you clear the color buffer via glClear function (by specifying GL_COLOR_BUFFER_BIT argument):
glClearColor(0, 1, 0, 1); // sets green color
glClear(GL_COLOR_BUFFER_BIT);
