How do glPushMatrix() and glPopMatrix() keep the scene the same?

前端 未结 3 1941
野的像风
野的像风 2020-12-09 05:56

I found some code online which will move a box across the screen, then reset it after the box hits the end of the screen.
Here is the code:



        
3条回答
  •  無奈伤痛
    2020-12-09 06:57

    OpenGL is a drawing API. When you call drawing functions, things are literally drawn to the framebuffer the very moment you issue the draw call -- well actually OpenGL batches up all the commands internally and processes them in order. But when OpenGL is about to process those drawing calls, it will draw to the framebuffer with the matrices set to the state at this specific position in the batch.

    So to reemphase this: OpenGL does not do any kind of scene management, it just draws things to the framebuffer in the order and way you issue the drawing commands. You send a triangle: OpenGL will transform and draw it. There's no scene internally built. Once you understood this it becomes trivial to understand how the matrix stack can do its "magic".

提交回复
热议问题