【发布时间】:2014-05-04 15:43:26
【问题描述】:
我正在使用 LWJGL 创建一个简单的体素事物作为一些练习,作为一个比较简单的项目来熟悉Kotlin。
所以我已经降低了体素渲染,除了渲染每个面具有不同纹理的体素。
它看起来没问题,直到我开始四处走动......然后:
如果有人需要整个 repo,那就是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:经过一些 more 测试后,事实证明问题在于具有不同纹理的任何两种不同类型的块相互作用......所以这可能不是每个人的事情,但而是面对面交互的东西?我不知道。
编辑 3:我决定尝试找出问题所在,因此我从代码中删除了 glTexCoords2f() 调用。不幸的是,问题仍然存在:
【问题讨论】:
标签: opengl graphics 3d lwjgl kotlin