我正在使用 LWJGL 创建一个简单的体素事物作为一些练习,作为一个适度简单的项目来熟悉Kotlin。
所以我已经降低了体素渲染,除了渲染每个面具有不同纹理的体素。
看起来不错,直到我开始四处走动......然后:
如果有人需要整个回购,它就在这里
至于相关的类,我不太确定什么是相关的,但这是生成glVertex3f和glTexture2f的东西:
public class Shape
{
class object
{
public fun CreateCube(x: Float, y: Float, z: Float, colour: ColourRGBA, tex: MutableList<TextureCoords>, size: Float)
{
val sheet: Spritesheet = Main.Instance!!.blocksprites
var textures: MutableList<TextureCoords> = 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:经过更多测试,事实证明问题在于具有不同纹理的任何两种不同类型的块相互作用......所以它可能不是每个人脸的事情,而是人脸互动的事情?我不知道。
编辑 3:我决定尝试查明问题,所以我从我的代码中删除了 glTexCoords2f() 调用。不幸的是,问题仍然存在: