void ChangeSize(int w, int h)
{
GLfloat fAspect;
// Prevent a divide by zero
if (h == 0)
h = 1;
// Set Viewport to window dimensions
glViewport(0, 0, w, h);
// Calculate aspect ratio of the window
fAspect = (GLfloat)w / (GLfloat)h;
// Set the perspective coordinate system
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
// field of view of 45 degrees, near and far planes 1.0 and 425
gluPerspective(45.0f, fAspect, 1.0, 425.0);
// Modelview matrix reset
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
glMatrixMode使用区别:
1、GL_PROJECTION:矩阵操作将作用于投影矩阵堆栈(用于定义修剪空间)
2、GL_MODELVIEW:矩阵操作将作用于模型视图矩阵堆栈(用于在场景中移动对象)
2、GL_TEXTURE:矩阵操作将作用于纹理矩阵堆栈(处理纹理坐标)