Modifying OpenGL axis system

前端 未结 2 1454
你的背包
你的背包 2021-01-01 04:03

I\'m using OpenGL with gluPerspective, what would I need to do to make it use an axis-system which the origin is top left instead of bottom left?

2条回答
  •  Happy的楠姐
    2021-01-01 04:50

    You can do this by flipping the y-axis of the projection matrix. So:

    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadMatrix( [1  0  0  0; 
                   0 -1  0  0; 
                   0  0  1  0; 
                   0  0  0  1] ); 
                // ^ pseudo-code, replace with actual matrix
    

    That ought to do it.

    You could also use a glMultMatrix call with the same matrix (instead of Push and then Load), but this way is more easily reversed (just call glPopMatrix on the GL_PROJECTION stack later).

    You can also use the same technique to flip any of the other axes; just put minus signs in the appropriate locations.

提交回复
热议问题