我编写C#代码来绘制边缘线条包围的立方体 使用OpenGL正交投影
表单加载时使用的代码
private void glControl_window_Load(object sender, EventArgs e)
{
GL.Enable(EnableCap.DepthTest);
GL.DepthFunc(DepthFunction.Less);
GL.Enable(EnableCap.DepthClamp);
GL.Enable(EnableCap.CullFace);
GL.FrontFace(FrontFaceDirection.Ccw);
GL.CullFace(CullFaceMode.Back);
GL.Enable(EnableCap.Normalize);
}
用于窗口涂料的代码
private void glControl_window_Paint(object sender, PaintEventArgs e)
{
GL.Clear(ClearBufferMask.ColorBufferBit |
ClearBufferMask.DepthBufferBit | ClearBufferMask.StencilBufferBit);
GL.MatrixMode(MatrixMode.Projection);
GL.LoadIdentity();
float aspectRatio;
if (Height == 0 || Width == 0) aspectRatio = 1f;
else aspectRatio = Width / (float)Height;
double W = 20 * aspectRatio / CameraZoomScale
, H = 20 / CameraZoomScale;
GL.Ortho(-0.5 * W, 0.5 * W, -0.5 * H, 0.5 * H, -600.0f, 600.0f);
GL.MatrixMode(MatrixMode.Modelview);
Matrix4 mv = Matrix4.LookAt(0, 0, 15, 0, 0, 0, 0, 1, 0);
// target coord 0,0,0 and eye coord 0,0,15
//Drawlines
GL.Enable(EnableCap.PointSmooth);
GL.Enable(EnableCap.LineSmooth);
GL.Enable(EnableCap.PolygonSmooth);
GL.Hint(HintTarget.LineSmoothHint,HintMode.Nicest);
GL.Enable(EnableCap.PolygonOffsetFill);
GL.Begin(PrimitiveType.Lines);
.
.
.
GL.End();
//Drawlines
GL.Begin(PrimitiveType.Triangles);
.
.
GL.End();
}
下图显示了深度测试精度的丢失方式。 https://i.stack.imgur.com/NCVzj.jpg
当我替换
GL.Ortho(-0.5 * W, 0.5 * W, -0.5 * H, 0.5 * H, -600.0f, 600.0f);
通过以下
GL.Ortho(-0.5 * W, 0.5 * W, -0.5 * H, 0.5 * H, -10.0f, 10.0f);
然后,每件事情都很精彩。但我有Z_coordinates等于600的立方体和另一个Z_coordinates等于0需要使用frustm 600的立方体
是否有另一种解决方案来绘制所有对象而不会失去深度精度?