Mipmap texturing

Hi forum,

Any support available from OF to load mipmap texturing ?

I did not find any example . Let me know if i miss it .

Thanks

Hey sajjad,

You won’t find OF examples for every part of opengl. If you can’t find it, you just need to write it yourself in straight opengl (most opengl code you can plug straight into your sketch).

Here’s the setup() code for automatic midmap texturing :

ofTexture* t = new ofTexture();
ofLoadImage(*t, "image.png);            
t->bind();
int textureTarget = t->getTextureData().textureTarget;
glTexParameteri(textureTarget, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(textureTarget, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glGenerateMipmap(GL_TEXTURE_2D); // automatically creates midmaps for the loaded texture
t->unbind();
1 Like

Thanks for the hint!

I am creating the mipmap texture in the following manner from the reference

http://nickhardeman.com/587/mipmap-textures-with-anisotropy-in-openframeworks-008/

The snippet that creates the mipmap texture is as follows:

void testApp::loadMipMapTexture( ofTexture& inTex, string inPath, float inAnisotropy )
{
   ofPixels pix;
   bool loaded = ofLoadImage(pix, inPath );
   
   inTex.allocate( pix.getWidth(), pix.getHeight(), ofGetGlInternalFormat(pix) );

   //get the texture data
   ofTextureData& texData = inTex.texData;
   
   if (texData.textureTarget == GL_TEXTURE_RECTANGLE_ARB)
   {
      texData.tex_t = pix.getWidth();
      texData.tex_u = pix.getHeight();
   }
   else
   {
      texData.tex_t = (float)(pix.getWidth()) / (float)texData.tex_w;
      texData.tex_u = (float)(pix.getHeight()) / (float)texData.tex_h;
   }
    
   ofSetPixelStorei(pix.getWidth(),pix.getBytesPerChannel(),pix.getNumChannels());
   
   glGenTextures(1, &texData.textureID);
   glBindTexture( texData.textureTarget, texData.textureID);
   glTexImage2D( texData.textureTarget, 0, texData.glTypeInternal, pix.getWidth(), pix.getHeight(), 0, ofGetGlFormat(pix), ofGetGlType(pix), pix.getPixels());
   glHint(GL_GENERATE_MIPMAP_HINT, GL_NICEST);
   glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
   glEnable(  texData.textureTarget);
   
   glGenerateMipmap(texData.textureTarget);
   
   glTexParameteri( texData.textureTarget, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
   glTexParameteri( texData.textureTarget, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
   
   // 1 means it does nothing //
   if( inAnisotropy >= 1 )
   {
      glTexParameterf( texData.textureTarget, GL_TEXTURE_MAX_ANISOTROPY_EXT, (GLfloat)inAnisotropy);
   }
   
   glDisable( texData.textureTarget );
}

I get the following error while exiting the application

 ofTexture: release(): something's wrong here, releasing unknown texture id 3

Any hint to track this ?

Thanks

Maybe make sure your texture textureTarget is TEXTURE_2D.

You’ll only get mipmaps for GL_TEXTURE_2D. GL_TEXTURE_RECTANGLE does not allow mipmaps.

1 Like