了解glutDisplayFunc和glutPostRedisplay之间的关系 [英] Understanding the relationship between glutDisplayFunc and glutPostRedisplay

查看:219
本文介绍了了解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时,重绘事件会与其他窗口事件(例如鼠标单击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之间的关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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