Win7 GLUT window doesn't receive events

I have created a simple Visual Studio Express 2010 C++ project using GLUT and OpenGL, it compiles and runs ok, except that the window it creates receives no events.. the close/minimize buttons don't do anything (not even mouseover) no context menu on the task bar on right click, and the window doesn't come to the foreground when clicked if partially covered.

The project is set up as a console application, I can close the program by closing the console.

I have this in main:

int main(int argc, char** argv) 
{
    glutInit(&argc, argv);
    glutInitWindowSize(window_width, window_height);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
    glutCreateWindow("MyApp");
    glutIdleFunc(main_loop_function);


    GLenum err = glewInit();
    if (GLEW_OK != err)
    {
      /* Problem: glewInit failed, something is seriously wrong. */
      fprintf(stderr, "Error: %s\n", glewGetErrorString(err));

    }
    if (GLEW_VERSION_1_3)
    {
      fprintf(stdout, "OpenGL 1.3 is supported \n");
    }
    fprintf(stdout, "Status: Using GLEW %s\n", glewGetString(GLEW_VERSION));



    GL_Setup(window_width, window_height);
    glutMainLoop();
}

Upvotes: 0

Views: 383

Answers (1)

tibur
tibur

Reputation: 11636

You miss a display callback. Could you try:

void display();

int main(int argc, char** argv) 
{
    glutInit(&argc, argv);
    glutInitWindowSize(window_width, window_height);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
    glutCreateWindow("MyApp");
    /// glutIdleFunc(main_loop_function);
    glutDisplayFunc(display);

    // ...

    glutMainLoop();
}

void display(){
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

    glutSwapBuffers();
}

Also, your idle function seems bad, if you effectively loop inside that function. Glut is callback oriented. You don't need to create a loop, but rather rely on idle, mouse, keyboard, display and resize callbacks. If you don't do so, you are going to miss window manager events.

EDIT:

If you want to create an animation, you could use:

glutIdleFunc(idleFunc);

void idleFunc(){
    glutPostRedisplay();
}

Upvotes: 1

Related Questions