I'm trying to calculate the delta time of my program. In main, I call:

glutInit(&argc, argv);

glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);

glutInitWindowSize(250, 250);
glutInitWindowPosition(100, 100);

glutCreateWindow("OpenGL Renderer");




My idle func:

void idle(void)
    int time;
    time = glutGet(GLUT_ELAPSED_TIME);
    delta = time - lastTime;
    lastTime = time;

I have these global variables:

int lastTime;
int delta;
float rtri; //Angle for triangle
float rquad; // Angle for quad

In the render method, I call:

// ...
glRotatef(rtri, 0.0f, 1.0f, 0.0f);
// ...
rtri += 0.2f * delta;
rquad -= 0.15f * delta;

Whith this code, I can't resize the window and if I press the close button, the window isn't responding anymore.

How can I fix this?

  • \$\begingroup\$ it's a wild guess but I think GLUT (or your code specifically) doesn't handle WM_RESIZE and WM_CLOSE messages. \$\endgroup\$
    – Ali1S232
    Dec 23 '12 at 21:34
  • \$\begingroup\$ but glut is also available on linux and linux has no WM_RESIZE and WM_CLOSE \$\endgroup\$
    – das_j
    Dec 23 '12 at 22:13
  • \$\begingroup\$ doesn't mean anything, there are too many codes which implement different behaviors for different operation systems. for example the whole window creation mechanism in windows in nothing like the one in linux. \$\endgroup\$
    – Ali1S232
    Dec 23 '12 at 22:55
  • 1
    \$\begingroup\$ What does your ReSizeGLScene function look like? What do you mean by "the window isn't responding any more?" Were these features working at an earlier time? If so, what code did you add since they were working? \$\endgroup\$ Dec 24 '12 at 4:19
  • \$\begingroup\$ Great idea, but in my ReSizeGLScene, I am just correcting the viewport. The Bug is there since I added the idle method (After further tests, I found out, it's not happening without the postGlutRedisplay(); but without this method, it won't redraw automatically. \$\endgroup\$
    – das_j
    Dec 24 '12 at 10:34

A friend helped me fixing it. He wrote a new Sample using double buffering. If you are interested, you can see the code at Pastebin.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .