MrXQ
MrXQ

Reputation: 740

How to set background color in OpenGL

The background color of my scene is black. How can I change this color?

Looks like I'm doing something wrong because glClearColor() function is not working: I tried to change the values but nothing happened. I'm new to OpenGL and programming in general.

#include <GL/glut.h>
void Ayarlar(void);
void CizimFonksiyonu(void);
int main(int argc, char **argv) {

    glutInit(&argc, argv);


    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); 
    glutInitWindowPosition(200, 200); 
    glutInitWindowSize(400, 400);
    glutCreateWindow("ilk OpenGL programim");
    glutDisplayFunc(CizimFonksiyonu);
    glutMainLoop();
    Ayarlar();


    return 0;
}
void Ayarlar(void) {

    glClearColor(1 ,0 ,0 , 1); 
    glShadeModel(GLU_FLAT);

}
void CizimFonksiyonu(void) {
    glClear(GL_COLOR_BUFFER_BIT);
    glFlush(); 

}

snapshot of sample

Upvotes: 2

Views: 2546

Answers (1)

Rabbid76
Rabbid76

Reputation: 210909

Ayarlar() has to be called be for glutMainLoop(). glutMainLoop enters the GLUT event processing loop and never returns. You have to set the OpenGL states before.

glutDisplayFunc(CizimFonksiyonu);

Ayarlar();
glutMainLoop();

Upvotes: 1

Related Questions