GLUP的原始OpenGL等价物?

如果没有Glu,我怎么能像GluPerspective一样呢? 谢谢

例如:gluPerspective(45.0,(float)w /(float)h,1.0,200.0);

void gluPerspective( GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar ) { GLdouble xmin, xmax, ymin, ymax; ymax = zNear * tan( fovy * M_PI / 360.0 ); ymin = -ymax; xmin = ymin * aspect; xmax = ymax * aspect; glFrustum( xmin, xmax, ymin, ymax, zNear, zFar ); } 

它在gluPerspective文档中相当清楚地解释了。 您只需构建适当的4×4转换矩阵并使用glMultMatrix将其乘以当前转换:

 void myGluPerspective(double fovy, double aspect, double zNear, double zFar) { double f = 1.0 / tan(fovy * M_PI / 360); // convert degrees to radians and divide by 2 double xform[16] = { f / aspect, 0, 0, 0, 0, f, 0, 0, 0, 0, (zFar + zNear)/(zNear - zFar), -1, 0, 0, 2*zFar*zNear/(zNear - zFar), 0 }; glMultMatrixd(xform); } 

请注意,OpenGL以列为主的顺序存储矩阵,因此上面的数组元素的顺序是从gluPerspective文档中的内容转换而来的。