…
I am trying to create a function that will change the background color of my window with a right mouse click. the function is supposed to cycle through three different colors with each click and on every fourth click revert to the original background color. so far it only changes to the first color and does nothing on any successive clicks. I am very new to OpenGL so I apologize for my ignorance. here is my function:
static void onclick (int button, int state, int x, int y)
{
int n = 0;
float m = 0.2;
if (button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN){
switch (n) {
case 0: {
glClearColor(0.0f, 0.0f, m, 0.1f);
redraw ();
n = 1;
break;
}
case 1: {
glClearColor(0.0f, m, 0.0f, 0.1f);
redraw ();
n = 2;
break;
}
case 2: {
glClearColor(m, 0.0f, 0.0f, 0.1f);
redraw ();
n = 3;
break;
}
case 3: {
glClearColor(0.0f, 0.0f, 0.0f, 0.1f);
redraw ();
n = 0;
break;
}
}
}
}