如何从单独的文件生成和使用mipmap?

时间:2012-02-15 03:58:22

标签: opengl

我有一些看起来像这样的代码:

_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#中,但应使用C API映射1:1)

我想如果我使用不同的mipmap缩减级别多次调用glTexImage2D,那么我就可以使用我的纹理和mipmapping,但 nothing 似乎被绘制到屏幕上(甚至不是黑色纹理。)

如果我只是将min过滤器更改为“最近”,则所有内容都会按预期呈现,所以这对于mipmapping来说肯定是个问题。

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

我想生成自己的mipmap的原因是因为它是一个spritemap,看起来精灵的某些边缘在调整大小时会一起流出,所以我制作了单独的图像,这些图像在精灵之间有硬边。

1 个答案:

答案 0 :(得分:1)

  

我想如果我用不同的mipmap缩减级别多次调用glTexImage2D,那么我就可以使用我的纹理和mipmapping

您的假设是正确的,这是您通常显式加载mipmap级别的方式。您是否使用gDEBugger测试了自己的计划,看看发生了什么?