0

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();
}
genpfault
  • 51,148
  • 11
  • 85
  • 139

1 Answers1

1

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();
}
tibur
  • 11,531
  • 2
  • 37
  • 39
  • I guess I need to add some kind of timer callback, as the display function is only being called once and then after a window event. – Vladimir Andrei Mitache Mar 09 '11 at 22:03
  • A glutPostRedisplay in the idle function should do the trick. However I suggest you have a look at GLFW, I think this should tease your expectations: You've got to implement your own event processing loop, no callbacks, and last but not lease built in support for OpenGL extensions and higher versions. – datenwolf Mar 09 '11 at 23:16