2014-05-04 48 views
0

我使用LWJGL創建一個簡單的素啄一些做法,如適度簡單的項目,以自己熟悉與Kotlin的OpenGL紋理毛刺與面孔

所以我已經得到了渲染素下來,除了渲染素與每個面不同的紋理。

看起來好了,直到我開始走動...然後: what

如果有人需要整個回購,這是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); 
     } 
    } 
} 

編輯:更多的測試後,我意識到,我Ø NLY得到怪異的毛刺時相機以上有問題的體素。我相似塊僅與側面露出放置在別處,並從底部看時,他們罰款:

相機略高於塊(問題升級的進一步遠離相機):enter image description here 相機下面塊:enter image description here

編輯2:經過一些更多測試,結果證明這個問題是相當於任何兩種不同類型的塊與不同的紋理相互作用......所以它可能不是一個面對面的事情,而是一個面對面互動的東西?我不知道。

編輯3:我決定嘗試找出問題,所以我刪除了glTexCoords2f()從我的代碼調用。不幸的是,問題依然存在:enter image description here

回答

0

所以。

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

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

基本上,降低最小視距啄,解決了這個問題。

+2

更精確地瞭解這樣做的原因。這種僞像被稱爲Z-fighting,它是由於多邊形太靠近在一起,或者是分辨率太低的z緩衝區。 OpenGL中的Z緩衝區是對數的,因此將非常靠近相機的近剪裁平面設置得更快。 – PeterT

+0

好吧,謝謝你的更深入的解釋。我實際上找到了解決方案,但我想我起初並不知道搜索條件 – zhiayang