作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我目前正在渲染一个天空盒,如下所示:
//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();
这似乎是渲染天空盒的一种极其低效的方法,因为我必须不断在纹理和四边形之间切换。此外,像这样渲染四边形往往会归因于视觉伪像,例如单像素线(四边形之间的接缝)。我听说过利用立方体贴图来提高效率,但在实现过程中遇到了困难。如果你们有任何建议,请随时为我指出正确的方向。谢谢。
最佳答案
立方体贴图基本上是将所有六个纹理放在一个纹理上。然后仅更改一次坐标并使用一次 glBindTexture 这将类似于:
GL11.glBindTexture(GL11.GL_TEXTURE_2D, skybox.getTextureID());
GL11.glBegin(GL11.GL_QUADS);
//Front Face
GL11.glTexCoord2f(0.25f, 0.25f);
GL11.glVertex3f(-player.x - offset, -player.y - offset, -player.z - offset);
GL11.glTexCoord2f(0.25f, 0.5f);
GL11.glVertex3f(-player.x - offset, -player.y + offset, -player.z - offset);
GL11.glTexCoord2f(0.0f, 0.5f);
GL11.glVertex3f(-player.x + offset, -player.y + offset, -player.z - offset);
GL11.glTexCoord2f(0.0f, 0.25f);
GL11.glVertex3f(-player.x + offset, -player.y - offset, -player.z - offset);
// Back Face
...
GL11.glEnd();
为了获得更多优化,请考虑在渲染天空盒时禁用深度缓冲区。您也可以停止清除颜色位。
关于java - LWJGL:渲染天空盒的更有效方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14362839/
我想在 iPhone 和 Android 上开发一个应用程序,它可以显示有关行星在宇宙中的位置和位置的详细信息。浏览谷歌我遇到了谷歌天空 map 。但我没有找到任何资源或 API 来执行此操作。所以请
我是一名优秀的程序员,十分优秀!