开发者

partially covered glut window doesn't redraw correctly after it is uncovered

Using free glut on windows 7 home ultimate with video card ati mobility radeon 5650

code snippet:

void ResizeFunction(int width, int height)
{
    glViewport(0, 0, width, height);
}

 void RenderFunction()
{
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    //...drawing code based on some flag, I draw a triangle or a rectangle
    //the flag is toggled on pressing 't' or 'T' key
    glutSwapBuffers(); //double buffering is enabled
    glutPostRedisplay();
}

void KeyboardFunction(unsigned char key, int x, int y)
{
    switch(key)
    {
        case 't':
        case 'T':
        {
            flag = !flag;
            glutPostRedisplay();
            break;
        }
        default:
    开发者_StackOverflow社区        break;
    }
}

problem: The triangle or the rectangle is drawn covering the entire window first time. But if I partially cover the glut window with another window (say, with some notepad window) and then uncover it, subsequently, when I toggle, the object is drawn only in the covered portion of the glut window. If I re-size the glut window, drawing works correctly as before.

Any help will be appreciated.

regards, fs


Glut only redraws on the screen when you tell it or when it decides. That is, if you don't do anything in the window, the scene is not redrawn. Advantage of this: less cpu/gpu usage. Disadvantage: Only good for non animated applications.

If you want to constantly update the screen (which is what is done in applications with lots of animations (games for example)), you can use glutIdleFunc

http://www.opengl.org/resources/libraries/glut/spec3/node63.html

That is in the beginning of the program when you set all the functions for glut, you also write:

glutIdleFunc(RenderFunction);

This way, when glut is idle, it keeps calling your render function.

If you want to render slower than possible (for example with a fixed frame rate), you could use a timer:

void RenderFunction()
{
    glutTimerFunc(YOUR_DELAY_IN_MS, RenderFunction, 0);
    /* rest of code */
}

and instead of glutIdleFunc(RenderFunction);, you write

`glutTimerFunc(YOUR_DELAY_IN_MS, RenderFunction, 0);`

To simply call the render function once (you could also just write RenderFunction() once) and the function keeps setting the timer for its next run.

As a side note, I suggest using SDL instead of glut.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜