我正在尝试加载一个PNG文件(其他格式是一个选项),以便在OpenTK中以.netstandard 1.4为目标的项目中呈现为纹理,该项目不支持System.Drawing库。
我能找到的每个opentk示例都依赖于system.drawing.bitmap类。
下面是一个我想在没有系统的情况下创建的方法的例子。

    void CreateFromBitmap(System.Drawing.Bitmap image)
    {
        image.RotateFlip(RotateFlipType.RotateNoneFlipY);

        GL.GenTextures(1, out name);
        GL.BindTexture(TextureTarget.Texture2D, name);

        // set pixel unpacking mode
        GL.PixelStore(PixelStoreParameter.UnpackSwapBytes, 0);
        GL.PixelStore(PixelStoreParameter.PackRowLength, 0);
        GL.PixelStore(PixelStoreParameter.UnpackAlignment, 1);
        GL.PixelStore(PixelStoreParameter.UnpackSkipRows, 0);
        GL.PixelStore(PixelStoreParameter.UnpackSkipPixels, 0);

        BitmapData data = image.LockBits(new System.Drawing.Rectangle(0, 0, image.Width, image.Height),
            ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

        // Requieres OpenGL >= 1.4
        GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.GenerateMipmap, 1); // 1 = True
        GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, data.Width, data.Height, 0,
                      OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, data.Scan0);

        image.UnlockBits(data);

        // set texture parameters - will these also be bound to the texture???
        GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)All.Repeat);
        GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)All.Repeat);

        GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)All.Linear);
        GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)All.LinearMipmapLinear);

        GL.TexEnv(TextureEnvTarget.TextureEnv, TextureEnvParameter.TextureEnvMode, (int)All.Decal);

        image = null;
        // Unbind
        GL.BindTexture(TextureTarget.Texture2D, 0);
    }

加载图像并将其格式化以用于opentk的另一种方法是什么?

最佳答案

用于将opentk转换为.netstandard2.0的中间选项
OpenTKCore
用于缺少的系统。图形库:两种选择
(a)https://github.com/zkweb-framework/zkweb.system.drawing[临时]
(b)https://github.com/dotnet/corefx/tree/master/src/System.Drawing.Common[即将正式]

09-26 06:25