VanDir
VanDir

Reputation: 2030

How to create mipmap manually?

I'm not fully satisfied with the quality obtained with the mipmap automatically generated with this line of code:

glTexParameterf(GL10.GL_TEXTURE_2D, GL11.GL_GENERATE_MIPMAP, GL10.GL_TRUE);

I thought to create (with Gimp) various scaled version of my texture for every texture used in my game. For example for a texture for a ball I will have:

ball256.png 256x256 px

ball128.png 128x128 px

ball64.png 64x64 px

ball32.png 32x32 px

ball16.png 16x16 px

1. Do you think is a good idea?

2. How can I create a single mipmapped texture from all these images?

Upvotes: 2

Views: 7416

Answers (1)

Andon M. Coleman
Andon M. Coleman

Reputation: 43369

This is not only a good idea, but it is a pretty standard practice (particularly in Direct3D)!

OpenGL implementations tend to use a standard box filter (uniformly weighted) when you generate mipmaps. You can use a nice tent fiter (bilinear) or even cubic spline (bicubic) when downsampling textures in image editing suites. Personally, I would prefer a lanczos filter since this is going to be done offline.

You may already be aware of this, but Direct3D has a standard texture format known as DDS (Direct Draw Surface) which allows you to pre-compute and pre-compress every mipmap level at content creation time instead of load-time. This decreases compressed texture load time and more importantly allows for much higher quality sample reconstruction during downsampling into each LOD. OpenGL also has a standardized format that does the same thing: KTX. I brought up Direct3D because although OpenGL has a standardized format very few people seem to know about it; DDS is much more familiar to most people.

If you do not want to use the standardized format I mentioned above, you can always load your levels of detail one-at-a-time manually by calling glTexImage2D (..., n, ...) where n is the LOD (0 is the highest resolution level-of-detail). You would do this in a loop for each LOD when you create your texture, this is actually how things like gluBuild2DMipmaps (...) work.

Upvotes: 6

Related Questions