Search code examples
javaopengl-eslibgdxtextures

libDGX doesn't draw texture with big dimension


I cannot draw big image in libGDX on my desktop. I have an image with dimension 9494x13082 pixels and use batch.draw(texture, 0, 0, width, height);. And instead of a texture libGDX draw a black square. If I compress the image to 60% or more, everything works fine. I tried to use TextureRegion, but that also doesn't work. Tell me please, what could be the problem. Maybe I haven't enough RAM?

I work in Linux, OpenGL ES 2.0, 2GB Ram, minimum RAM for Java - 1GB, maximum - 2GB.


Solution

  • first: opengl texture dimension is equals h&w; Even if you do not have a width equal to height, then the largest adjacency is also considered for another, and eventually the square is given to that memory.

    Second: It is best for your picture to be no larger than 2048 * 2048. I think the maximum is 4096 * 4096.

    opengl 1 not supported POT. libgdx chang you texture to POT. so, the best texture size is power of tow. with this parameter disable force POT for libgdx.

    Texture.setEnforcePotImages(false);
    

    now your solution:

    You have to split your photo into smaller pieces. For example 2048 * 2048(POT) then pack them with TEXTURE_PACKER. Then draw it where you need it.

    Note that if you are using a compression tool, note that the compressed file is different with the graphical compression. So you do not have less memory space with jpg or png. you should use texture compressor like : etc1, etc2, ktx , ....

    i write the example code for you:

       // in this sample my image is 5*4 (5*4 - 2048*2048)
       for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 4; j++) {
                  batch.draw(texture[i,j], i*2048, j*2048, width, height);
            }
        }