0

我现在读了一本书。它关于OpenGL。有一个使用恶魔加载纹理的示例。我已经实现了书中 1:1 的代码。但是 iluFlipImage 函数会导致图形问题。我将 .Net Framework 4.0 与 toa-framework 2.1 一起使用


翻转

翻转


没有翻转

没有翻转


    public void LoadTexture(string textureName, string path)
    {
        int devIlId;
        Il.ilGenImages(1, out devIlId);
        Gl.glBindTexture(Gl.GL_TEXTURE_2D, devIlId);

        if (!Il.ilLoadImage(path))
        {
            System.Diagnostics.Debug.Assert(false,
            "Could not open file, [" + path + "].");
        }

        Ilu.iluFlipImage();

        var width = Il.ilGetInteger(Il.IL_IMAGE_WIDTH);
        var height = Il.ilGetInteger(Il.IL_IMAGE_HEIGHT);
        var textureId = Ilut.ilutGLBindTexImage();

        System.Diagnostics.Debug.Assert(textureId != 0);
        Il.ilDeleteImages(1, ref devIlId);
        _textureStorage.Add(textureName, new Texture(textureId, path, width, height));
    }
4

1 回答 1

0
    public void LoadTexture(string name, string path)
    {
        var bitmap = new Bitmap(path);
        var bitmapData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height),
                                         ImageLockMode.ReadOnly, PixelFormat.Format32bppRgb);
        int textureId;
        Gl.glGenTextures(1, out textureId);
        Gl.glBindTexture(Gl.GL_TEXTURE_2D, textureId);
        Gl.glTexImage2D(Gl.GL_TEXTURE_2D, 0, Gl.GL_RGBA8, bitmap.Width, bitmap.Height, 0, Gl.GL_BGRA, Gl.GL_UNSIGNED_BYTE, bitmapData.Scan0);
        Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_LINEAR);
        Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_LINEAR);
        _textureStorage.Add(name, new Texture(textureId, path, bitmap.Width, bitmap.Height));

        bitmap.UnlockBits(bitmapData);
        bitmap.Dispose();
    }
于 2012-02-08T20:59:27.717 回答