1
由于某些原因,我不能在openGL中绘制任何过去z> 1的东西。 Z缓冲区工作正常,我暂时停留了一段时间。 我认为问题是gluPerspective,但它仍然无法正常工作。 我可以看到0和1之间的任何东西,代码apears剪切的三角形。 对不起,我英文很差。OpenGL剪辑Z> 1.0
#include <iostream>
#include <GL/glut.h>
using namespace std;
void idle() {
glutPostRedisplay();
}
void changeSize(int w, int h) {
// Prevent a divide by zero, when window is too short
// (you cant make a window of zero width).
if(h == 0)
h = 1;
float ratio = 1.0* w/h;
// Use the Projection Matrix
glMatrixMode(GL_PROJECTION);
// Reset Matrix
glLoadIdentity();
// Set the viewport to be the entire window
glViewport(0, 0, w, h);
// Set the correct perspective.
gluPerspective(0, ratio, 0.1, 1000.0);
// Get Back to the Modelview
glMatrixMode(GL_MODELVIEW);
}
void renderScene(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glBegin(GL_TRIANGLES);
glVertex3f(-0.5,-0.5,0.0);
glVertex3f(0.5,0.0,0.0);
glVertex3f(0.0,0.5,2.0);
glEnd();
glutSwapBuffers();
}
int main(int argc, char **argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowSize(800,600);
glutCreateWindow("OpenGL");
glutDisplayFunc(renderScene);
glutReshapeFunc(changeSize);
glutIdleFunc(idle);
glEnable(GL_DEPTH_TEST);
glutMainLoop();
return 0;
}
调用'gluPerspective'应该导致错误,什么都不做?如果属实,那么根本没有变换,连接到第三点的两条线被剪切,最后显示出一个奇怪的四边形。 – 2012-03-29 20:23:29
它活着,谢谢! – TheVTM 2012-03-29 20:23:35
@Tim:OP确实看到了一些东西,因为gluPerspective调用的0 FOV使它在不改变投影矩阵的情况下尽早返回,从而使其保持一致。因此,可见体积是框-1,-1,-1至+ 1,+ 1,+ 1,这也解释了剪切。 – datenwolf 2012-03-29 21:15:38