我有这个功能,它在屏幕的左下角绘制一个小的3D轴坐标系,但根据我面前的情况,它可能会被剪裁.
例如,我在地面上绘制了一个平坦的地形,在XZ平面上Y = 0.摄像机位于Y = 1.75(模拟一般人的身高).如果我抬头,它工作正常,如果我向下看,它会被地平面夹住.
向上看:http://i.stack.imgur.com/Q0i6g.png
往下看:http://i.stack.imgur.com/D5LIx.png
void Axis3D::DrawCameraAxisSystem(float radius,float height,const Vector3D rotation) { if(vpHeight == 0) vpHeight = 1; glMatrixMode(GL_PROJECTION); glLoadIdentity(); glViewport(0,vpWidth,vpHeight); gluPerspective(45.0f,1.0 * vpWidth / vpHeight,1.0f,5.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0.0f,0.0f,-3.0f); glRotatef(-rotation.x,0.0f); glRotatef(-rotation.y,0.0f); DrawAxisSystem(radius,height); }
我认为现在有几个主要功能与问题相关:
glutDisplayFunc(renderScene); glutReshapeFunc(changeSize); void changeSize(int width,int height) { if(height == 0) height = 1; glMatrixMode(GL_PROJECTION); glLoadIdentity(); glViewport(0,width,height); gluPerspective(60.0f,1.0 * width / height,1000.0f); glMatrixMode(GL_MODELVIEW); } void renderScene(void) { glClearColor(0.7f,0.7f,0.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); changeSize(glutGet(GLUT_WINDOW_WIDTH),glutGet(GLUT_WINDOW_HEIGHT)); glLoadIdentity(); SceneCamera.Move(CameraDirection,elapsedTime); SceneCamera.LookAt(); SceneAxis.DrawCameraAxisSystem(0.03f,0.8f,SceneCamera.GetRotationAngles()); glutSwapBuffers(); }
建议?
解决方法
而不是禁用深度测试,你可以只是glClear(GL_DEPTH_BUFFER_BIT);在渲染叠加层之前.然后,无论深度信息是什么都消失了,但像素仍然存在.但是,您的叠加层仍会正确呈现.