理解glutDisplayFunc和glutPostRedisplay的关系 [英] Understanding the relationship between glutDisplayFunc and glutPostRedisplay

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

问题描述

在阅读红皮书时我发现:

When reading the redbook I found:

glutDisplayFunc(void (*func)(void)) 是第一个也是最重要的事件你会看到回调函数.每当 GLUT 确定窗口的内容需要重新显示,回调函数由 glutDisplayFunc() 注册的是执行.因此,你应该把您需要重绘的所有例程显示回调中的场景功能.

glutDisplayFunc(void (*func)(void)) is the first and most important event callback function you will see. Whenever GLUT determines that the contents of the window need to be redisplayed, the callback function registered by glutDisplayFunc() is executed. Therefore, you should put all the routines you need to redraw the scene in the display callback function.

如果你的程序改变了内容的窗户,有时你会调用 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 时,重绘事件与其他窗口事件(例如鼠标单击等)一起排队.基本上你的 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的关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆