Mipmap on a 3dPrimitive

I’m trying to apply a mipmap on a 3dPrimitive without any result. I did not found much documentation online, except this gist https://gist.github.com/tgfrerer/dae32894b8ef785e6786 by @tgfrerer from this PR https://github.com/openframeworks/openFrameworks/pull/3146

Based on this information, I’ve done this

//in .h
// ofSpherePrimitive sphere;
// ofLight light;
// ofTexture mTex;
// ofEasyCam cam;
void ofApp::setup(){

    //important, ofDisableArbText has to be called before the image is loaded
    mTex.setTextureMinMagFilter(GL_LINEAR_MIPMAP_LINEAR, GL_NEAREST);


void ofApp::draw(){

As mipmap image I’ve used this jpg file https://en.wikipedia.org/wiki/Mipmap#/media/File:MipMap_Example_STS101.jpg

The result is in this picture

Any ideas?

Hi there!

I think you are misinterpreting the objective of ofTexture::generateMipmap.

The idea is that it will create a mipmap from a normal texture. What you are loading, is a precomputed mipmap.

Try to load something like this. You’ll see the difference. :slight_smile:

Hi @hubris, thank you for your reply. I’ve three questions:

  1. Does ofTexture::generateMipmap create a mipmap like that one that I’ve linked(that one with the satellite) starting from a singular image? If yes, there is no need to compose mipmaps by hand, correct?
  2. Using the satellite image, and uncommenting the mTex.generateMipmap(); does not change anything. Theoretically, it should not create the mipmap, using the precomputed one. Am I correct?

3)Using the picture that you suggested, It looks really pixelated when using mipmaps.

If i comment out these 2 lines and I disable the mipmap,

    //mTex.setTextureMinMagFilter(GL_LINEAR_MIPMAP_LINEAR, GL_NEAREST);

The image has a better definition

Why this behaviour?

  1. Yes, generateMipmap uses the openGL function to create mipmaps, which creates and stores something like the one with the satellite. Correct, there is no need to create by your own.

  2. AFAIK, there’s no way to load a precomputed mipmap to OF and use it accordingly. That’s why it gets rendered like the one you posted.

  3. The idea of a mipmap is “to increase rendering speed and reduce aliasing artifacts. A high-resolution mipmap image is used for high-density samples, such as for objects close to the camera. Lower-resolution images are used as the object appears farther away.” [Wiki]

In your example, because you are setting the magFilter to GL_NEAREST, you will get that pixelated look. And since OF default is GL_LINEAR, you get that smooth (interpolated look).

Before you load an texture, you can do ofTexture::enableMipmap, which will do everything for you. But, just to make this post more complete, let me give you some examples. :slight_smile:

With no mipmaps (but using OFs default GL_LINEAR)

As you can see, on the top of the sphere, which is also a bit far away, you get a bit of artefacts and aliasing issues.

Using ofTexture::enableMipmap before loading the texture

Now, those artefacts are gone.

Using ofTexture::generateMipmap after you load the texture and

ofTexture.setTextureMinMagFilter(GL_LINEAR_MIPMAP_LINEAR, GL_NEAREST)

for the filters.

As you can see, you get the perks of the mipmap, but because you set the mag to GL_NEAREST, on where the texture is closer, you’ll get that pixelated look.

At last, but not least:

Using ofTexture::generateMipmap after you load the texture and

ofTexture.setTextureMinMagFilter(GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR)

for the filters.

Using GL_LINEAR basically gives you the second example.

I hope this helps. If you have any doubts, fell free to ask. :smiley:

1 Like

Hello @hubris, many thanks for this comprehensive answer, it is everything clear now.

1 Like