Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: weird program functionality with freeglut

  1. #1
    Intern Contributor
    Join Date
    Jun 2013

    weird program functionality with freeglut

    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:
    Code :
    int main(int argc, char **argv){
        glutInit(&argc, argv);
        glutCreateWindow("Test Programs");
        return 0;

    here is my fragment shader:
    Code :
    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:
    Code :
    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?

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Apr 2010
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts