Modifying OpenGL axis system

会有一股神秘感。 提交于 2019-11-29 15:53:08

问题


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?


回答1:


I would say direct operating on the projection matrix is a clean way for this operation. But if by any chance you need an alternative:

You can just use glScalef(1.f, -1.f, 1.f) to flip the axis.

This is also just an operation on the GL_MODELVIEW or GL_PROJECTION matrix (whatever is currently active).




回答2:


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.



来源:https://stackoverflow.com/questions/2866731/modifying-opengl-axis-system

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!