-2

I've already gotten the skybox to work, except that it takes in six files. I would like to find out how to use 1 file instead of six. I've looked all over the internet and cannot find anything that will work. Here is the loadCubeMap function that puts the images into the cubemap :

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;
}
Ryan Reed
  • 9
  • 1
  • 3
  • What image? Do you know the layout? Is question about how to extract parts of image from `TextureData`? Please be more specific. – keltar Mar 31 '15 at 07:01
  • @keltar from the code I see that his current cubemap is in 6 png images. I believe he wants it in a single file – ratchet freak Mar 31 '15 at 07:02
  • @ratchetfreak I can see that, but it could mean different things. Zipping 6 pngs is 1 file; using multisurface file format is one file; merging all images into single 2D is one file too. If last option is used, image may contain different layouts (set all 6 in one row, or whatever else), and loader have to be aware of that. – keltar Mar 31 '15 at 07:41
  • Sorry, I was very unspecific about my question, the image format would be like this : https://www.google.com/search?q=cubemap&es_sm=93&source=lnms&tbm=isch&sa=X&ei=K9kaVfznBZDxoATQh4CACw&ved=0CAcQ_AUoAQ&biw=1366&bih=677#imgrc=nBJaTKcS8ZyR0M%253A%3B-S1bEujNRIgPeM%3Bhttp%253A%252F%252Fwww.f-lohmueller.de%252Fpov_tut%252Fbackgrnd%252Fim%252FCubemap_2_2048x1536.jpg%3Bhttp%253A%252F%252Fforum.bioware.com%252Ftopic%252F541812-info-a-simple-cube-map-cheat-sheet-to-help-you-edit-them%252F%3B2048%3B1536 – Ryan Reed Mar 31 '15 at 17:28
  • With explicitly specified layout you can calculate rectangles for each cubemap side, e.g. first side is on (0, h/3, w/4, h/3*2). Then you need to allocate memory buffer for smaller image (one side of cubemap), copy pixels from your `TextureData` into it (row by row), and pass resulting buffer to `glTexImage2D`. Repeat for all 6 sides. My experience with java is nonexistent, but it is all the same with any language. By the way given layout isn't very good - almost half of pixels are unused space, which takes memory and decoding time (but only during loading). – keltar Apr 01 '15 at 05:56

1 Answers1

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.

new Objekt
  • 414
  • 3
  • 8