View Full Version : weird program functionality with freeglut

06-28-2013, 01:09 PM
hi all. i was trying to make a cube that ive drawn on the screen flicker between 2 colors, but instead it changes color whenever i click on the screen. here are the relevant portions of my code.

here is the freeglut initialization:

int main(int argc, char **argv){
glutInit(&argc, argv);

glutCreateWindow("Test Programs");




return 0;


here is my fragment shader:

const char *fshader =
"#version 430 core\n"
"out vec4 fColor;\n"
"uniform vec4 Color;\n"
"void main()\n"
"fColor = Color;\n"

and here is the part of my display function that should cause it to flicker:

if (!colorswitch)
glUniform4f(colorloc, color1[0], color1[1], color1[2], color1[3]);
colorswitch = !colorswitch;
else if (colorswitch)
glUniform4f(colorloc, color2[0], color2[1], color2[2], color2[3]);
colorswitch = !colorswitch;

i just want the cube to flicker between colors. any ideas?

carsten neumann
06-28-2013, 02:05 PM
GLUT does not constantly redraw, it only does so when needed (i.e. in response to events from the OS that indicate a redraw is necessary, a mouse click seems to be considered such an event) or when you explicitly ask it to redraw (by calling glutPostRedisplay()). If you want to redraw constantly, register an idle function (glutIdleFunction) that just calls glutPostRedisplay.