openGL中移动窗口时如何重绘图片?

发布于 2024-08-26 03:32:51 字数 326 浏览 6 评论 0原文

我在 Windows 上用 openGL 画了一张图。现在,每当我在窗口上按住鼠标按钮并移动它时,我的图片总是会变形。我不知道openGL中有什么函数可以帮助我在窗口移动时重绘图片。有人可以帮忙吗?

我尝试过这个但似乎不起作用:

void myDisplay()
{
   .....
}

void reshape(int x, int y)
{
   glutPostRedisplay();
}

int main()
{
   .....
   glutDisplayFunc(myDisplay);
   glutReshapeFunc(reshape);
}

I have drawn a picture with openGL on my windows. Now whenever I hold the mouse button on the windows and move it, my picture always got distorted. I don't know what function in openGL that can help me redraw the picture while the windows is moved. Anybody could help?

I tried this but seems not work:

void myDisplay()
{
   .....
}

void reshape(int x, int y)
{
   glutPostRedisplay();
}

int main()
{
   .....
   glutDisplayFunc(myDisplay);
   glutReshapeFunc(reshape);
}

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

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

发布评论

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

评论(3

一世旳自豪 2024-09-02 03:32:51

第一个(通常也是唯一的)必要步骤是停止使用过剩。 glut 主要面向生成静态显示,因此它会尝试累积更改,然后仅在状态再次“稳定”时重绘,例如当您完成调整窗口大小时。这曾经是有道理的,但现在大多数情况下已经不再有道理了。

鉴于距离 glut 上次更新已经过去了大约 10 年,过时的设计目标也就不足为奇了。这并没有改变这样一个事实:它是精心编写的,旨在防止您想要的事情发生。如果您愿意,您可能可以重写它以更好地满足您的期望,但是使用其他旨在执行您想要的操作(或至少更接近您想要的操作)的东西几乎肯定会更简单。

The first (and usually only) necessary step is to to quit using glut. glut is oriented primarily toward producing a static display, so it attempts to accumulate changes and then redraw only when the state has "stabilized" again, such as when you're done resizing the window. That made sense at one time, but mostly doesn't anymore.

Given that it's been around 10 years since glut was last updated, out of date design goals are hardly a surprise. That doesn't change the fact that it's carefully written to prevent what you want from happening. If you wanted to, you could probably rewrite it to fit your expectations better, but it'll almost certainly be quite a bit simpler to use something else that's designed to do what you want (or at least something closer to what you want).

手长情犹 2024-09-02 03:32:51

添加 glutIdleFunc 函数

int main()
{
   .....
   glutDisplayFunc(myDisplay);
   glutIdleFunc(myDisplay);
   glutReshapeFunc(reshape);
}

Add glutIdleFunc function

int main()
{
   .....
   glutDisplayFunc(myDisplay);
   glutIdleFunc(myDisplay);
   glutReshapeFunc(reshape);
}
独自唱情﹋歌 2024-09-02 03:32:51

对我有用的解决方案是在 WM_MOUSEMOVE 上调用 MoveWindow 之后跳过 InvalidateRect/RedrawWindow 函数的执行(我没有使用 glut)。因为通常在所有鼠标/键盘事件之后执行 InvalidateRect(wnd,0,0) 是有意义的,但显然在 MoveWindow 之后调用它会导致窗口内容“留在后面”拖动。

Solution that worked for me was to skip the execution of InvalidateRect/RedrawWindow functions after calling MoveWindow on WM_MOUSEMOVE (I'm not using glut). Because usually it makes sense to execute InvalidateRect(wnd,0,0) after all mouse/keyboard events, but apprently calling it after MoveWindow causes the window contents to "stay behind" dragging.

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