gpt4 book ai didi

java - 较远的平面渲染在较近的平面前面

转载 作者:行者123 更新时间:2023-11-30 04:33:45 27 4
gpt4 key购买 nike

我有一个 libgdx 应用程序,我在其中创建了一个由立方体组成的迷宫。当我渲染底部蓝色和顶部红色面时,底部一个会渲染在顶部面的前面。两个面具有相同的法 vector 。

我可以切换远近剪裁平面吗?

这是我设置相机的方法:

public PerspectiveCamera updateCamera() {
if (camera == null) {
float aspectRatio = Gdx.graphics.getWidth() / Gdx.graphics.getHeight();
camera = new PerspectiveCamera(67f, aspectRatio, 1);
this.setActive(true);
}
return camera;
}

enter image description here Bottom is clearly below top

最佳答案

我只是忘记添加深度测试。

添加到 create() 方法:

Gdx.gl.glEnable(GL10.GL_DEPTH_TEST);
Gdx.gl.glDepthFunc(GL10.GL_LESS);

添加到 render() 方法:

Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

关于java - 较远的平面渲染在较近的平面前面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13985425/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com