Search code examples
libgdxsizetextures

libgdx What texture size?


What size for my textures should I use so it looks good on android AND desktop and the performance is good on android? Do I need to create a texture for android and a texture for desktop?


Solution

  • The best way (regarding performance + quality) would be to use mipmaps. That means you start with a big Texture(for example 1024*1024px) and downsample it to a fourth of its size, until you reach a 1x1 image. So you have a 1024*1024, a 512*512, a 256*256... and a 1*1 Texture.

    As much as i know you only need to provide the bigest (1024*1024 in the example above) Texture and Libgdx will create the mipmap chain at runtime.
    OpenGL under the hood then decides which Texture to use, based on the Pixel to Texel ratio.
    Taking a look at the Texture API, it seems like there is a 2 param constructor, where the first param is the FileHandle for the Texture and the second param is a boolean, indicating, whether you want to use mipmaps or not. As much as i remember you also have to set the right TextureFilter.
    To know what TextureFilter to you, i suggest to read this article.