I am loading a Texture2d from a stream:

public static Texture2D GetTexture(GraphicsDevice dev, System.Drawing.Bitmap bmp) {
    Texture2D texture;
    using (MemoryStream s = new MemoryStream())
        bmp.Save(s, System.Drawing.Imaging.ImageFormat.Jpeg);
        s.Seek(0, SeekOrigin.Begin);
        texture = Texture2D.FromStream(dev, s);

    return texture;

I want to generate a mipmap for the texture, as my texture looks bad when viewed from afar. How do I do this?


2 Answers 2



If you create your mipmap programatically, you will experiance such a problem with no doubt!

You have to create your mipmap in your 3D software, which will render each size seperatly,resampling with raster image editing tools and with programming will reduce the the pixel size without care and deletes a whole row or a whole col which hurts the edges and important spots in your raster, so you need to resample, during the render process, I hope you have a 3D model and the texture you are talking about is rendered from which.

In this case :

if your 3D software supports mipmap creation it is easy to be done, though without this ability, you may play with camera location, do the math!

Some 3D software support scripting I personally use a phyton code to create the mipmaps in Blender.

Tell me if you need a phyton code in case you use Blender.

Good luck



There is some API support: XNA Game Studio.

A thread about it: XNA 4 Texture2D.GenerateMipmaps() missing.

However, this will for sure NOT have the generation right. Because these functions will not apply gamma correction intrinsically:

You can also discard it if the slight imprecision is not of importance to you.

Without using the API generating mipmaps can be done manually but it is a piece of work to implement, you need to either do it on the CPU and map/copy to the correct parts of the texture. Or do it on the GPU using render targets and then using "resource copy" API to set the mips: https://stackoverflow.com/questions/11172218/mipmapping-with-generating-textures-in-xna.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .