部分覆盖的过剩窗口在未被覆盖后无法正确重绘

发布于 2024-12-02 06:20:15 字数 996 浏览 3 评论 0原文

在带有显卡ati mobile radeon 5650windows 7 home Ultimate上使用free glut

代码片段:

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:
            break;
    }
}

问题:绘制的三角形或矩形覆盖了第一次整个窗口。但是,如果我用另一个窗口(例如,用一些记事本窗口)部分覆盖过剩窗口,然后揭开它,随后,当我切换时,对象仅在过剩窗口的被覆盖部分中绘制。如果我重新调整过剩窗口的大小,绘图将像以前一样正常工作。

任何帮助将不胜感激。

问候, FS

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:
            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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夕色琉璃 2024-12-09 06:20:15

Glut 仅在您告诉它或它做出决定时才会在屏幕上重绘。也就是说,如果您不在窗口中执行任何操作,则场景不会重新绘制。这样做的优点:更少的 cpu/gpu 使用。缺点:仅适用于非动画应用程序。

如果您想不断更新屏幕(这是在具有大量动画的应用程序(例如游戏)中所做的),您可以使用 glutIdleFunc

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

那就是在程序的开头当你设置了 glut 的所有函数时,你还写了:

glutIdleFunc(RenderFunction);

这样,当 glut 空闲时,它会不断调用你的 render 函数。

如果您希望渲染速度比可能的慢(例如使用固定帧速率),您可以使用计时器:

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

而不是 glutIdleFunc(RenderFunction);,您只需编写

`glutTimerFunc(YOUR_DELAY_IN_MS, RenderFunction, 0);`

一次即可调用渲染函数 (您也可以只编写 RenderFunction() 一次),该函数将继续为下一次运行设置计时器。

附带说明一下,我建议使用 SDL 而不是 glut。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文