Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>glPushMatrix</code> duplicates the matrix on top of the stack (you're always working with the top one). Any other transformation you are doing modifies this top matrix, the duplicated one. When you do <code>glPopMatrix</code> we are back to the original matrix.</p> <p>For example, suppose you want to draw a car. You set up the matrix to draw the body of the car, let's call it <code>M1</code>. Now, you want to draw one wheel. You can either compute <code>M2</code> - the matrix needed for the wheel to be displayed correctly - or, since the wheel is relative to the body of the car (thus, there is a matrix <code>M3</code> such that <code>M2 = M1 * M3</code>) you modify <code>M1</code>. But the car has 4 wheels, you need to keep a copy of <code>M1</code>. You do this by doing a <code>glPushMatrix</code>, you get back the copy by doing a <code>glPopMatrix</code>.</p> <p><img src="https://i.stack.imgur.com/DXUHw.png" alt="glPushMatrix and glPopMatrix"></p> <p>When you draw anything on the screen, you are giving coordinates in object space. To really display something, those coordinates need to be transformed. For that we have some matrices.</p> <p>In the wheel example, you have only one wheel geometry but because you are using different matrices, there will be four wheels drawn. <code>glPushMatrix</code> and <code>glPopMatrix</code> work only with the matrix, the actual vertex data is kept into the GPU, each <code>glVertex</code> sends another one there and it cannot be removed. See the following image, the matrices are used only for transforming object coordinates to world coordinates (actually, all matrices can be pushed into a stack)</p> <p><img src="https://i.stack.imgur.com/yzCRP.png" alt="multiple matrices"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload