0
我目前渲染天空盒,像這樣的更有效的方法:LWJGL:渲染天空盒
//Front Face
GL11.glBindTexture(GL11.GL_TEXTURE_2D, skybox[0].getTextureID());
GL11.glBegin(GL11.GL_QUADS);
GL11.glTexCoord2f(1f, 0.0f);
GL11.glVertex3f(-player.x - offset, -player.y - offset, -player.z - offset);
GL11.glTexCoord2f(1f, 1f);
GL11.glVertex3f(-player.x - offset, -player.y + offset, -player.z - offset);
GL11.glTexCoord2f(0.0f, 1f);
GL11.glVertex3f(-player.x + offset, -player.y + offset, -player.z - offset);
GL11.glTexCoord2f(0.0f, 0.0f);
GL11.glVertex3f(-player.x + offset, -player.y - offset, -player.z - offset);
GL11.glEnd();
// Back Face
GL11.glBindTexture(GL11.GL_TEXTURE_2D, skybox[2].getTextureID());
GL11.glBegin(GL11.GL_QUADS);
GL11.glTexCoord2f(0.0f, 0.0f);
GL11.glVertex3f(-player.x - offset, -player.y - offset, -player.z + offset);
GL11.glTexCoord2f(1f, 0.0f);
GL11.glVertex3f(-player.x + offset, -player.y - offset, -player.z + offset);
GL11.glTexCoord2f(1f, 1f);
GL11.glVertex3f(-player.x + offset, -player.y + offset, -player.z + offset);
GL11.glTexCoord2f(0.0f, 1f);
GL11.glVertex3f(-player.x - offset, -player.y + offset, -player.z + offset);
GL11.glEnd();
// Top Face
GL11.glBindTexture(GL11.GL_TEXTURE_2D, skybox[4].getTextureID());
GL11.glBegin(GL11.GL_QUADS);
GL11.glTexCoord2f(1f, 1f);
GL11.glVertex3f(-player.x - offset, -player.y - offset, -player.z - offset);
GL11.glTexCoord2f(0.0f, 1f);
GL11.glVertex3f(-player.x + offset, -player.y - offset, -player.z - offset);
GL11.glTexCoord2f(0.0f, 0.0f);
GL11.glVertex3f(-player.x + offset, -player.y - offset, -player.z + offset);
GL11.glTexCoord2f(1f, 0.0f);
GL11.glVertex3f(-player.x - offset, -player.y - offset, -player.z + offset);
GL11.glEnd();
// Bottom Face
GL11.glBindTexture(GL11.GL_TEXTURE_2D, skybox[5].getTextureID());
GL11.glBegin(GL11.GL_QUADS);
GL11.glTexCoord2f(1f, 0f);
GL11.glVertex3f(-player.x - offset, -player.y + offset, -player.z - offset);
GL11.glTexCoord2f(1f, 1f);
GL11.glVertex3f(-player.x - offset, -player.y + offset, -player.z + offset);
GL11.glTexCoord2f(0f, 1f);
GL11.glVertex3f(-player.x + offset, -player.y + offset, -player.z + offset);
GL11.glTexCoord2f(0f, 0f);
GL11.glVertex3f(-player.x + offset, -player.y + offset, -player.z - offset);
GL11.glEnd();
// Right face
GL11.glBindTexture(GL11.GL_TEXTURE_2D, skybox[3].getTextureID());
GL11.glBegin(GL11.GL_QUADS);
GL11.glTexCoord2f(0.0f, 0.0f);
GL11.glVertex3f(-player.x - offset, -player.y - offset, -player.z - offset);
GL11.glTexCoord2f(1f, 0.0f);
GL11.glVertex3f(-player.x - offset, -player.y - offset, -player.z + offset);
GL11.glTexCoord2f(1f, 1f);
GL11.glVertex3f(-player.x - offset, -player.y + offset, -player.z + offset);
GL11.glTexCoord2f(0.0f, 1f);
GL11.glVertex3f(-player.x - offset, -player.y + offset, -player.z - offset);
GL11.glEnd();
// Left Face
GL11.glBindTexture(GL11.GL_TEXTURE_2D, skybox[1].getTextureID());
GL11.glBegin(GL11.GL_QUADS);
GL11.glTexCoord2f(1f, 0.0f);
GL11.glVertex3f(-player.x + offset, -player.y - offset, -player.z - offset);
GL11.glTexCoord2f(1f, 1f);
GL11.glVertex3f(-player.x + offset, -player.y + offset, -player.z - offset);
GL11.glTexCoord2f(0.0f, 1f);
GL11.glVertex3f(-player.x + offset, -player.y + offset, -player.z + offset);
GL11.glTexCoord2f(0.0f, 0.0f);
GL11.glVertex3f(-player.x + offset, -player.y - offset, -player.z + offset);
GL11.glEnd();
這似乎是要去約渲染天空盒極其低效的方式,因爲我要保持紋理之間切換四邊形。此外,像這樣渲染四邊形往往歸因於像單個像素線(四邊形之間的接縫)的視覺僞像。我聽說利用立方體貼圖來提高效率,但我正在努力實現。如果你們有任何建議,請隨時指出我的方向。謝謝。