Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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");

InitGL();

glutDisplayFunc(DrawGLScene);
glutReshapeFunc(ReSizeGLScene);
glutIdleFunc(idle);

glutMainLoop();

My idle func:

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

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?

share|improve this question
    
it's a wild guess but I think GLUT (or your code specifically) doesn't handle WM_RESIZE and WM_CLOSE messages. –  Ali.S Dec 23 '12 at 21:34
    
but glut is also available on linux and linux has no WM_RESIZE and WM_CLOSE –  das_j Dec 23 '12 at 22:13
    
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. –  Ali.S Dec 23 '12 at 22:55
1  
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? –  ktodisco Dec 24 '12 at 4:19
    
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. –  das_j Dec 24 '12 at 10:34
add comment

1 Answer

up vote -1 down vote accepted

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.