PDA

View Full Version : weird program functionality with freeglut



sandbucket
06-28-2013, 02: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);
glutInitDisplayMode(GLUT_RGBA);
glutInitWindowSize(512,512);
glutInitContextVersion(4,3);
glutInitContextProfile(GLUT_CORE_PROFILE);

glutCreateWindow("Test Programs");

init();


glutDisplayFunc(display);

glutMainLoop();

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"
"{\n"
"fColor = Color;\n"
"}\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, 03: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.