How to update opengl modelview matrix with my own 4x4 matrix?

二次信任 提交于 2020-01-24 02:41:11

问题


I have 4x4 matrix for object's transformations.

float mat44[16];

But i don't know how to update OpenGL ModelView matrix using my matrix. should i use glTranslatef()/glRotatef() with relavant values from my matrix or should i use glLoadMatrix(),glMultMatrix() ? Pls help. Thanks.


回答1:


If you want to apply your transformation to current transformation already in OpenGL matrix stack, then you should write:

glMultMatrixf(mat44);

But if you want to discard what's currently on top of OpenGL matrix stack and use your own transformation, then you should write:

glLoadMatrixf(mat44);



回答2:


For OpenGL-2.1 and earlier use glLoadMatrix or glMultMatrix, depending on the task at hand.

For OpenGL-3 and later set them as the right uniform for your shader using one of the glUniformMatrix variants.



来源:https://stackoverflow.com/questions/9092010/how-to-update-opengl-modelview-matrix-with-my-own-4x4-matrix

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