我正在使用LWJGL创建一个简单的体素作为一些练习,作为一个中等简单的项目来熟悉Kotlin。
所以我已经将体素渲染下来了,除了渲染每个面部具有不同纹理的体素。
看起来好吧,直到我开始走动......然后:
如果有人需要整个回购,那就是here
至于相关的类,我不太确定什么是相关的,但是这里有生成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()调用。不幸的是,问题仍然存在:
答案 0 :(得分:1)
所以
GLU.gluPerspective(67.0f, (width / height).toFloat(), 0.0001f, 1000.0f)
GLU.gluPerspective(67.0f, (width / height).toFloat(), 0.5f, 1000.0f)
基本上,减少最小视距,解决问题。