0

I'm using Visual Studio Express 2010, with freeglut_static.lib linked (in Properties>Linker>Input>Additional Dependencies, version 2.8.0) and FREEGLUT_STATIC defined. The code builds and compiles, though I did have to tweak a bunch of properties to get it to link. I am running Window-7 64 bit, though the code was compiled as a 32 bit executable.

The code is

// -----------------------------------
static void reshape(int w, int h) { 
    // free old buffers; allocate new ones; update global state
    // etc...
    ;
}

static void display() { glutSwapBuffers(); }

int main(int argc; char **argv)
{
    glutInitWindowSize(500, 500);
    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
    glutInit(argc, argv);
    glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_GLUTMAINLOOP_RETURNS);
    glutDisplayFunc(display);
    glutReshapeFunc(reshape);
    // glutIdleFunc(display);
    glutCreateWindow("Hmm");
    glutMainLoop();
    // free resources
    return 0;
}
// ----------

The issue is that neither display() or reshape() are ever called. When the window is resized, the upper left part of it remains white and the rest becomes black.

Uncommenting the glutIdleFunc() line causes the display function to be called now, and resizing the window leaves it all black. However, reshape() is still not invoked.

I've stared at the freeglut source code and can't see what the problem is. I don't know enough about the windows API to debug freeglut, unfortunately.

Any ideas why the callbacks aren't working?

Walt Donovan
  • 357
  • 1
  • 10

1 Answers1

3

glutDisplayFunc sets the function for the current window. You have to call glutCreateWindow before glutDisplayFunc.

flyx
  • 35,506
  • 7
  • 89
  • 126
  • Thanks, that fixed the problem! (Every time I start coding with a new API, I always have a bug of this nature to start with...) – Walt Donovan May 11 '12 at 07:57
  • Hmm, how come the callback worked for glutIdleFunc() though? That definitely made it much harder for me to see the problem. – Walt Donovan May 11 '12 at 07:58
  • Because the idle function is global. See http://www.opengl.org/documentation/specs/glut/spec3/node63.html#SECTION000818000000000000000 – flyx May 11 '12 at 09:55