本文介绍了了解glutDisplayFunc和glutPostRedisplay之间的关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在阅读红皮书时,我发现:

When reading the redbook I found:

如果程序更改了内容 的窗户,有时你会 调用glutPostRedisplay(), 给glutMainLoop()推一下 在其注册的显示回调 下一个机会

If your program changes the contents of the window, sometimes you will have to call glutPostRedisplay(), which gives glutMainLoop() a nudge to call the registered display callback at its next opportunity

哪个时间应该调用glutPostRedisplay()?从这一段,我不明白为什么需要它的功能.

Which are times in which glutPostRedisplay() should be called? From this paragraph, I don't understand why its functionality is needed.

推荐答案

glutDisplayFunc.这包括一个人调用glutPostRedisplay的时间:)

glutDisplayFunc is called whenever your window must be redrawn. This includes the time when one calls glutPostRedisplay :)

什么时候需要重新绘制窗口?

When does a window need to be redrawn?

  • 大小改变时
  • 当它可见时
  • 当其中某些部分可见时
  • 移动时

但是如果您的显示函数在x; y位置(其中x; y;位置)绘制了三角形,该怎么办?是由鼠标位置决定的?在这种情况下,每当鼠标右移时,您都必须要求系统重新绘制窗口?这就是为什么要从MouseFunc()调用glutPostRedisplay的原因.实际上,当您调用glutPostRedisplay时,重绘事件会与其他窗口事件(例如鼠标单击ets)一起排队.本质上,您的mainLoop会从该队列中选择事件并调用其处理程序

But what if your display function paints a triangle at position x;y where x;y; are determined by the mouse position? In this case you must ask the system to redraw the window whenever the mouse is moved right? That's why you'll call glutPostRedisplay from MouseFunc(). Actually when you call glutPostRedisplay, the redraw event is queued along with other window-events, like mouse click ets. Essentially what your mainLoop does it pick events from that queue and call their handlers

这篇关于了解glutDisplayFunc和glutPostRedisplay之间的关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 06:16