1

我有一个 C# .NET 应用程序,我用它创建了一个自定义图像显示控件。每个图像显示代表它自己的显示上下文并使用 glDrawPixels 绘制图像(是的,我知道使用纹理会更好,我计划在未来使用,但这个应用程序已经太远了,我的时间有限)。

我现在正试图让两个图像同时平移。也就是说,当一个图像下移十个像素时,第二个图像下移十个像素。像这样:

imageOne.YPan -= 10;
imageTwo.YPan -= 10;
imageOne.Invalidate(); //This forces a redraw.
imageTwo.Invalidate(); //This forces a redraw.

好吧,这就是我遇到的问题。只有一个图像显示正在重绘。如果我在两个 Invalidate 调用之间暂停并使暂停持续时间至少为 110 毫秒,则两者都将重绘,但不会同时重绘。所以看起来第二张图片总是试图赶上第一张。另外,110 毫秒的停顿会使动作减慢太多。

我尝试将每个图像的更新和失效放在它自己的线程中,但这没有帮助。

在绘图开始时,我使适当的上下文是当前的,最后我调用 swapbuffers()。我尝试在绘图函数的末尾添加一个 glFinish,但没有任何变化。

会不会是显卡的问题?我被困在使用只有 openGL 1.4 的集成 gpu 上。

希望我已经提供了足够的细节,可以找到我的问题的答案。

4

2 回答 2

1

Its difficult telling what's wrong with what you do since you give so little detail. Here are some pointers which may help.
- before doing something in a context, make sure you make it the current one. If you want to pan two contexts, make the first one current, pan it and then make the second one current and pan it. These is no real reason why this should not work.
- If it looks like there is a timing problem, adding glFinish() at strategic places may help weed the problem out
- As should always be done, on occasions call glError() and see that everything went well.
- I'm not sure how this is done in the framework you're talking about but you should make sure that both contexts get a swapBuffers() call for every frame.

于 2008-11-26T02:11:06.823 回答
0

Invalidate不强制立即重绘。它将窗口标记为无效,当消息队列用完其他消息时,将创建并处理一条绘制消息。但这在您完成处理当前消息并返回主消息循环之前不会发生,并且它可能会延迟更多。

一般来说,OpenGL 动画是在内部Control.OnPaint(或在Control.Paint事件的处理程序中)进行所有绘制的规则的一个例外。

于 2011-04-11T23:23:51.073 回答