Understanding the relationship between glutDisplayFunc and glutPostRedisplay

前端 未结 2 1483
情话喂你
情话喂你 2020-12-31 14:09

When reading the redbook I found:

glutDisplayFunc(void (*func)(void)) is the first and most important event callback function you will see. When

相关标签:
2条回答
  • 2020-12-31 14:16

    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?

    • When its size changes
    • when it becomes visible
    • when some parts of it become visible
    • when it is moved
    • etc

    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

    0 讨论(0)
  • 2020-12-31 14:28

    The function you pass to glutDisplayFunc is only called it is needed: that means when the window is resized, or when an another window has hidden it. If you use glutMouseFunc, for instance, you perhaps want to update (redraw) your window content according to that clic. Also, if you draw animations, you need to call glutPostRedisplay from your idle function.

    0 讨论(0)
提交回复
热议问题