-2

我已经让天空盒工作了,除了它需要六个文件。我想了解如何使用 1 个文件而不是 6 个文件。我在整个互联网上都查看过,找不到任何可行的方法。这是将图像放入立方体贴图中的 loadCubeMap 函数:

public int loadCubeMap(String[] textureFiles){
    int texID = GL11.glGenTextures();
    GL13.glActiveTexture(GL13.GL_TEXTURE0);
    GL11.glBindTexture(GL13.GL_TEXTURE_CUBE_MAP, texID);

    for(int i=0;i<textureFiles.length;i++){
        TextureData data = decodeTextureFile("res/" + textureFiles[i] + ".png");
        GL11.glTexImage2D(GL13.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL11.GL_RGBA, data.getWidth(), data.getHeight(), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, data.getBuffer());
    }
    GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
    GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
    textures.add(texID);
    return texID;
}
4

1 回答 1

2

You can combine the 6 sides of the skybox into a single texture any way you want. All you need to do is set the texture coordinates of each side of the skybox to the coresponding section of the image. If you make you skybox image TopBottomLeftRightFrontBack all in a row (6:1 aspect ratio) then all you need to do is set the top face as

{0.0,0.0} {0.1666,0.0} {0.1666,1.0} {0.0,1.0}

and your bottom face as

{0.1666,0.0} {0.3332,0.0} {0.3332,1.0} {0.1666,1.0}

and so on for the other faces.

于 2015-03-31T17:43:39.333 回答