OpenGL纹理毛刺与面孔

我正在使用LWJGL来创建一个简单的体素thingy作为一些练习,作为一个适度的简单项目来熟悉Kotlin 。

所以我已经得到了体素渲染下来,除了渲染每个脸上不同纹理的体素。

看起来不错,直到我开始移动…然后: 什么

如果有人需要整个回购,就在这里

至于相关的类,我不太确定什么是相关的,但这里是生成glVertex3f和glTexture2f的东西:

public class Shape { class object { public fun CreateCube(x: Float, y: Float, z: Float, colour: ColourRGBA, tex: MutableList, size: Float) { val sheet: Spritesheet = Main.Instance!!.blocksprites var textures: MutableList = arrayListOf() if (tex.size == 1) { for (i in 0 .. 5) textures.add(tex[0]) } else textures.addAll(tex) // bottom face // bottom face (0, 1) GL11.glColor4f(colour.red.toFloat(), colour.green.toFloat(), colour.blue.toFloat(), colour.alpha.toFloat()); GL11.glTexCoord2f(textures[0].x, textures[0].y + sheet.GetUniformSize()); GL11.glVertex3f(x, y, z + size); GL11.glTexCoord2f(textures[0].x + sheet.GetUniformSize(), textures[0].y + sheet.GetUniformSize()); GL11.glVertex3f(x + size, y, z + size); GL11.glTexCoord2f(textures[0].x + sheet.GetUniformSize(), textures[0].y); GL11.glVertex3f(x + size, y, z); GL11.glTexCoord2f(textures[0].x, textures[0].y); GL11.glVertex3f(x, y, z); // top face (2, 3) GL11.glColor4f(colour.red.toFloat(), colour.green.toFloat(), colour.blue.toFloat(), colour.alpha.toFloat()); GL11.glTexCoord2f(textures[1].x, textures[1].y + sheet.GetUniformSize()); GL11.glVertex3f(x, y + size, z); GL11.glTexCoord2f(textures[1].x + sheet.GetUniformSize(), textures[1].y + sheet.GetUniformSize()); GL11.glVertex3f(x + size, y + size, z); GL11.glTexCoord2f(textures[1].x + sheet.GetUniformSize(), textures[1].y); GL11.glVertex3f(x + size, y + size, z + size); GL11.glTexCoord2f(textures[1].x, textures[1].y); GL11.glVertex3f(x, y + size, z + size); // front face (4, 5) GL11.glColor4f(colour.red.toFloat(), colour.green.toFloat(), colour.blue.toFloat(), colour.alpha.toFloat()); GL11.glTexCoord2f(textures[2].x, textures[2].y + sheet.GetUniformSize()); GL11.glVertex3f(x, y, z); GL11.glTexCoord2f(textures[2].x + sheet.GetUniformSize(), textures[2].y + sheet.GetUniformSize()); GL11.glVertex3f(x + size, y, z); GL11.glTexCoord2f(textures[2].x + sheet.GetUniformSize(), textures[2].y); GL11.glVertex3f(x + size, y + size, z); GL11.glTexCoord2f(textures[2].x, textures[2].y); GL11.glVertex3f(x, y + size, z); // back face (6, 7) GL11.glColor4f(colour.red.toFloat(), colour.green.toFloat(), colour.blue.toFloat(), colour.alpha.toFloat()); GL11.glTexCoord2f(textures[3].x, textures[3].y); GL11.glVertex3f(x, y + size, z + size); GL11.glTexCoord2f(textures[3].x + sheet.GetUniformSize(), textures[3].y); GL11.glVertex3f(x + size, y + size, z + size); GL11.glTexCoord2f(textures[3].x + sheet.GetUniformSize(), textures[3].y + sheet.GetUniformSize()); GL11.glVertex3f(x + size, y, z + size); GL11.glTexCoord2f(textures[3].x, textures[3].y + sheet.GetUniformSize()); GL11.glVertex3f(x, y, z + size); // left face (8, 9) GL11.glColor4f(colour.red.toFloat(), colour.green.toFloat(), colour.blue.toFloat(), colour.alpha.toFloat()); GL11.glTexCoord2f(textures[4].x, textures[4].y + sheet.GetUniformSize()); GL11.glVertex3f(x + size, y, z); GL11.glTexCoord2f(textures[4].x + sheet.GetUniformSize(), textures[4].y + sheet.GetUniformSize()); GL11.glVertex3f(x + size, y, z + size); GL11.glTexCoord2f(textures[4].x + sheet.GetUniformSize(), textures[4].y); GL11.glVertex3f(x + size, y + size, z + size); GL11.glTexCoord2f(textures[4].x, textures[4].y); GL11.glVertex3f(x + size, y + size, z); // right face (10, 11) GL11.glColor4f(colour.red.toFloat(), colour.green.toFloat(), colour.blue.toFloat(), colour.alpha.toFloat()); GL11.glTexCoord2f(textures[5].x, textures[5].y + sheet.GetUniformSize()); GL11.glVertex3f(x, y, z + size); GL11.glTexCoord2f(textures[5].x + sheet.GetUniformSize(), textures[5].y + sheet.GetUniformSize()); GL11.glVertex3f(x, y, z); GL11.glTexCoord2f(textures[5].x + sheet.GetUniformSize(), textures[5].y); GL11.glVertex3f(x, y + size, z); GL11.glTexCoord2f(textures[5].x, textures[5].y); GL11.glVertex3f(x, y + size, z + size); } } } 

编辑:经过多一点测试,我意识到,我只有当相机是在问题的体素上方的奇怪的小故障。 我把类似的块放在其他地方,只露出侧面,从底部看,他们很好:

相机略高于方块(问题升级相机越远): 在这里输入图像说明 摄像机下面的块: 在这里输入图像说明

编辑2:经过一些更多的测试,事实certificate这个问题是相当于任何两种不同的纹理相互作用的块…所以它可能不是一个面对面的事情,而是一个面对面的互动的东西? 我不知道。

编辑3:我决定尝试找出问题,所以我从代码中删除了glTexCoords2f()调用。 不幸的是,这个问题依然存在: 在这里输入图像说明

所以。

GLU.gluPerspective(67.0f, (width / height).toFloat(), 0.0001f, 1000.0f)

如何GLU.gluPerspective(67.0f, (width / height).toFloat(), 0.5f, 1000.0f)

基本上,减少分视距离,解决问题。