我目前正在渲染一个这样的天空盒:
//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();
这似乎是一种非常低效的渲染天空盒的方法,因为我必须不断在纹理和四边形之间切换。此外,像这样渲染四边形往往会归因于视觉伪影,例如单像素线(四边形之间的接缝)。我听说过使用立方体贴图来提高效率,但我在努力实现。如果你们有任何建议,请随时指出我正确的方向。谢谢。