#include<windows.h>#include<glut.h>float M[3][3] = {{1.0,0.0,0.0},{0.0,1.0,0.0},{0.0,0.0,1.0}};float(*pM) [3] = M;void myDisplay(void) { glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glPushMatrix(); glMultMatrixf(pM); glColor3f(1.0,1.0,1.0); glRectf(-0.5f, -0.5f, 0.5f, 0.5f); glPopMatrix(); glFlush(); } int main(int argc, char *argv[]) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE); glutInitWindowPosition(100, 100); glutInitWindowSize(400, 400); glutCreateWindow("第一个OpenGL程序"); glutDisplayFunc(&myDisplay); glutMainLoop(); return 0; }原本显示一个白色的矩形,进行M矩阵变换(glMultMatrixf(pM);)后,没有任何显示,为什么?
glMultMatrix 假设当前矩阵式C那么用矩阵M 调用glMultMatrix 对顶点v的变换就从原来的C × v变成C × M × v你的代码调用glMultMatrix 后看不到那个画的方框是因为单位矩阵要是4x4的,可以调用glGetDoublev(GL_MODELVIEW_MATRIX, modelMatrix);查看当前矩阵的值