steave
steave

Reputation: 395

opengl render texture and switch between with mipmap or not

I use this code to switch between images with mipmaps or not:

if ( tex->hasMipMaps ) {
            glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
            glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR );
        }
        else {
            glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
            glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
        }

however this happens: enter image description here

the table is rendered without mipmap,but when I change the register texture code to :

   // if ( tex->hasMipMaps ) {
                glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
                glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR );
            //}
            //else {
            //  glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
            //  glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
            //}

here is the result: enter image description here the mipmap works,but my font texture is kind missing,is there a way to render both textures that with mipmaps such as models and some textures without mipmaps such as font,particles? do I need to call glTexParameteri to switch some states?

Upvotes: 2

Views: 676

Answers (1)

genpfault
genpfault

Reputation: 52123

Texture objects without a complete set of mipmaps will (generally) render white as you have seen.

You'll have to enable/disable mipmapping on a per-mesh level (assuming one texture per mesh) if some of your textures don't have mipmaps.

Upvotes: 1

Related Questions