2012-02-15 19 views
0

我有一些代碼,看起來像這樣:如何從單獨的文件生成和使用mipmap?

_bfTex = new Texture(TextureTarget.Texture2D, true); 
_bfTex.Image2D("Textures/sphax/terrain128.png", 0); 
_bfTex.Image2D("Textures/sphax/terrain64.png", 1); 
_bfTex.Image2D("Textures/sphax/terrain32.png", 2); 
_bfTex.Image2D("Textures/sphax/terrain16.png", 3); 
_bfTex.Image2D("Textures/sphax/terrain8.png", 4); 
_bfTex.Image2D("Textures/sphax/terrain4.png", 5); 
_bfTex.Image2D("Textures/sphax/terrain2.png", 6); 
_bfTex.Image2D("Textures/sphax/terrain1.png", 7); 
_bfTex.SetMinFilter(TextureMinFilter.NearestMipmapNearest); 
_bfTex.SetMagFilter(TextureMagFilter.Nearest); 
_bfTex.SetParameter(TextureParameterName.TextureWrapS, TextureWrapMode.ClampToEdge); 
_bfTex.SetParameter(TextureParameterName.TextureWrapT, TextureWrapMode.ClampToEdge); 

Image2D功能如下:

public void Image2D(Bitmap bmp, int mipmapReductionLevel = 0) 
{ 
    var rect = new Rectangle(0, 0, bmp.Width, bmp.Height); 
    var data = bmp.LockBits(rect, ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); 

    GL.TexImage2D(TextureTarget.Texture2D, mipmapReductionLevel, PixelInternalFormat.Rgba, data.Width, data.Height, 0, 
     OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, data.Scan0); 

    bmp.UnlockBits(data); 
} 

(代碼是C#,但應映射1:1與C API)

我想如果我叫glTexImage2D幾次不同的紋理映射減少的水平,那麼我可以用我的質地,紋理映射,但沒有似乎可以得出ŧ o屏幕(甚至沒有黑色紋理)。

如果我只是將最小過濾器更改爲「最接近」,那麼所有渲染都如預期那樣良好,所以這絕對是mipmapping的一個問題。

如果我用glGenerateMipmap來生成我的mipmap,那也可以。

我想生成我自己的mipmap的原因是因爲它是一個精靈圖,它看起來像一些精靈的邊緣在調整大小期間一起流血,所以我製作了獨立的圖像,在精靈之間有硬邊緣。

回答

1

我想如果我叫glTexImage2D幾次不同的紋理映射減少的水平,那麼我可以用我的紋理mipmapping貼圖

你的假設是正確的,這是怎麼你通常顯式地加載mipmap級別。你用gDEBugger測試了你的程序,看看發生了什麼?

相關問題