Mipmaps with Slick

Started by Grandmaster B, August 17, 2008, 22:49:18

Previous topic - Next topic

Grandmaster B

Hi!

I use LWJGL 2 and Slick for texture loading but unfortunately it seems as no mipmaps are created by Slick. How do you create mipmaps?

Grandmaster B

I've come to the following solution:

tex = TextureLoader.getTexture(format, new FileInputStream(texfile));
tex.bind();

int width = (int)tex.getImageWidth();
int height = (int)tex.getImageHeight();

byte[] texbytes = tex.getTextureData();
int components = texbytes.length / (width*height);

ByteBuffer texdata = ByteBuffer.allocate(texbytes.length);
texdata.put(texbytes);
texdata.rewind();

MipMap.gluBuild2DMipmaps(GL11.GL_TEXTURE_2D, components, width, height, components==3 ? GL11.GL_RGB : GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE,texdata);

GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);


For anisotropic filtering add the line:
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, EXTTextureFilterAnisotropic.GL_TEXTURE_MAX_ANISOTROPY_EXT, 8);