你们知道这个问题的原因是什么吗?从正视图看,它看起来很好。
正交视图:
透视图:
可能相关的代码:
//Global variable
float tx = 0, tz = 0, tSpeed = 1.0;
bool isOrtho = true;
float ONear = -20.0, OFar = 20.0;
float PNear = 1.0, PFar = 41.0;
float ptx = 0, pty = 0, ptSpeed = 0.1;
float pry = 0, prSpeed = 1.0;
void projection() {
glMatrixMode(GL_PROJECTION); //refer to projection matrix
glLoadIdentity(); //reset projection matrix
glTranslatef(ptx, pty, 0.0); //translation for projection
glRotatef(pry, 0.0, 1.0, 0.0); //rotate for projection
if (isOrtho) {
//Ortho View
glOrtho(-20.0, 20.0, -20.0, 20.0, ONear, OFar); //Ortho view
}
else {
//Perspective view
gluPerspective(45, 1.0, -1.0, 1.0);
glFrustum(-20.0, 20.0, -20.0, 20.0, PNear, PFar);
}
}
void display(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
projection();
glMatrixMode(GL_MODELVIEW);
lighting();
drawRobot();
}
1条答案
按热度按时间6rvt4ljy1#
针对
gluPerspective
状态的Glu文档:ZNear
指定从查看器到近剪裁平面的距离**(始终为正值)**。
(重点是我的)。
您的代码
gluPerspective(45, 1.0, -1.0, 1.0);
为zNear传递了-1.0,它不在允许的值范围内。