LWJGL Forum

Programming => OpenGL => Topic started by: Martijn on October 06, 2014, 20:09:54

Title: Problems using mipmapping on 3d textures
Post by: Martijn on October 06, 2014, 20:09:54
Hi guys,

I'm working on my engine for quite a well now, recently got a 3D textured terrain working, but I can't seem to get mipmapping working on 3D textures.

The problem is when i use auto-generate mipmaps I get really weird results:

Mipmapping off:
(http://i61.tinypic.com/25qg7b8.jpg)

Mipmapping on:
(http://i59.tinypic.com/6pnvpc.jpg)

The code used to make the textures is the same for both the water (texture2D) and terrain (texture3D)

GL11.glTexParameteri(t, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR);
GL11.glTexParameteri(t, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR);
GL11.glTexParameteri(t, GL12.GL_TEXTURE_MAX_LEVEL, mipMapCount);
GL11.glTexParameteri(t, GL14.GL_GENERATE_MIPMAP, (autoMipMap) ? GL11.GL_TRUE : GL11.GL_FALSE);


Is there something I'm missing or doing wrong? Or maybe somebody knows a tutorial about mipmapping 3D textures, please let me know.  :)
Title: Re: Problems using mipmapping on 3d textures
Post by: Cornix on October 06, 2014, 20:22:14
Perhaps try to show all mipmap levels or maybe write them to an image file.
One problem might be that the mipmaps work just fine but they are so tiny that they become a single pixel because of how far you are zoomed out.
Title: Re: Problems using mipmapping on 3d textures
Post by: quew8 on October 07, 2014, 07:25:24
Make sure you're setting the GL_GENERATE_MIPMAP flag before calling glTexImage2D(). Looking at the docs, with this setting set to true, mipmaps will only be generated when there is a change to the level 0 image.

Also you could try using glGenerateMipmap() to see whether that produces the same effects.
Title: Re: Problems using mipmapping on 3d textures
Post by: Martijn on October 13, 2014, 18:05:09
I've tried using glGenerateMipmap() on my code but it obviously failed.

Seems like I'm using legacy code to generate mipmaps after reading this: https://www.opengl.org/wiki/Common_Mistakes#Automatic_mipmap_generation (https://www.opengl.org/wiki/Common_Mistakes#Automatic_mipmap_generation)

I will rewrite some of my code, read some stuff about texture storage (later opengl versions) and will let you guys know if it helped.
Title: Re: Problems using mipmapping on 3d textures
Post by: abcdef on October 14, 2014, 10:48:15
Have you confirmed the image is indeed a mipmap image? My code is below, I do things slightly differently to you


private void registerTexture()
    {
        bindTexture();

        renderer.glTexImage2D(renderer.GL_TEXTURE_2D,0,image.getType(),width,height,0,image.getTarget(),renderer.GL_UNSIGNED_BYTE,textureData);

        if(hasMipsMaps)
        {
            renderer.glGenerateMipMaps(renderer.GL_TEXTURE_2D);
        }

        renderer.glPixelStorei(renderer.GL_UNPACK_ROW_LENGTH,0);
        renderer.glPixelStorei(renderer.GL_UNPACK_ALIGNMENT,1);

        renderer.glTexParameteri(renderer.GL_TEXTURE_2D,renderer.GL_TEXTURE_WRAP_S,clampModeS);
        renderer.glTexParameteri(renderer.GL_TEXTURE_2D,renderer.GL_TEXTURE_WRAP_T,clampModeT);

        renderer.glTexParameteri(renderer.GL_TEXTURE_2D,renderer.GL_TEXTURE_MAG_FILTER,filterModeMag);
        renderer.glTexParameteri(renderer.GL_TEXTURE_2D,renderer.GL_TEXTURE_MIN_FILTER,filterModeMin);

        unBindTexture();
    }