View Full Version : gluBuild2DMipmaps replacement code

06-07-2004, 06:45 AM
Hi. I remember seeing some code a while back that would replace gluBuild2DMipmaps. It claimed it produced better image quality and that it was also faster than gluBuild2Dmipmaps. I am not sure if this was from Mesa or something else. Now I can't seem to find that code.

I am wondering if anyone here knows where to find that code or something similar. I tried to download the Mesa library but the download link is not working.

If someone could point me to some code or even describe the technique used to create high quality mipmaps, that would be helpful.


06-07-2004, 07:18 AM

I don't have the code, but one way to create better quality mipmaps would be using a standard box filter to scale the image down to half, and then applying a subtle sharpen filter on the result. Then just proceed to lower levels until you reach 1x1.


06-07-2004, 08:04 AM
The best way to do it is to prepare your textures correctly in the first place.

First, make sure you save them in power-of-two sizes, in BGRA format (and specify that when uploading the images).

Second, use an image format that supports MIP maps natively, or extend an existing format to support MIP maps. DDS is a good format for this.

Third, if you use compression, pre-compress the images using offline compression. S3TC compression is pretty much required for modern art, because of its lower bandwidth requriements and the higher apparent detail afforded.

If your images somehow come from a live source where you can't control them, then you might not be able to do this, of course.

06-07-2004, 09:40 AM
Thanks for your replies.

This is actually not for an OpenGL application, but I am an OpenGL programmer in new territory.
I am building a texture conversion tool that takes TGAs as inputs and outputs to another format that can store mipmaps in the file.

I would be happy even with the quality of gluBuild2DMipmaps. I am not so much looking for a way to improve on gluBuild2DMipmaps as I am looking for a way to do exactly what it does with my own code (if the image quality was improved, that would be a plus).

I am not sure how to resize an image to a smaller size without simply omitting pixels. I assume that gluBuild2DMipmaps does some kind of averaging of pixels when resizing the image. This is primarily what I'm interested in.

JustHanging, can you explain what you mean by "standard box filter"?

06-07-2004, 10:50 AM
have a look into glu's sourcecode. you can find it in the cvs repository of mesa. the mipmap generation functions can be found exactly here (http://freedesktop.org/cgi-bin/viewcvs.cgi/mesa/Mesa/src/glu/mesa/mipmap.c?view=markup) .

06-07-2004, 01:15 PM
I took a look at that mesa code, but I ended up just coming up with something by myself that works very well. I also might try JustHanging's suggestion of adding a sharpen filter for even better results.

Thanks for your replies.

06-08-2004, 12:39 AM
Just use a better filter than the simple box filter gluBuild2DMipMaps uses. A gaussian would probably work well.

And make sure you use gamma correct blending of samples if the texture isn't in linear space (fairly common).

06-08-2004, 08:16 AM
I might also add, that if you end up using two filters in a row (like rescale+sharpen), you'll get better quality if you maintain precision between them. For example, a 2x2 box filter for rescaling a 8 bit image results in a 10 bit image. Applying sharpen on that before dropping back to 8 bit propably improves the quality a bit.


06-09-2004, 05:42 PM
using the sgis_generate_mipmap extension is very quick, most likely far quicker than any code you can come up with yourself (though the quality aint so great).
on a related note what programs can i use to specify various textures to be used as the mipmaps, eg like dxtex.exe (comes with directx, which i cant seem to find on the net, unless i download the whole directx sdk 100+mb) and will save the texture (with mipmaps) in dds format (or something)
cheers zed

06-09-2004, 11:18 PM
I think nividia had some dds tools for download as well