右下角的图像应该有一个透明的背景。
我加载我的Notch 通过这些函数生成 PNG:
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);
}
public void Image2D(string filename, int mipmapReductionLevel = 0)
{
Image2D(new Bitmap(filename), mipmapReductionLevel);
}
我的片段着色器看起来像这样:
#version 330
in vec2 TexCoord0;
uniform sampler2D TexSampler;
void main()
{
gl_FragColor = texture2D(TexSampler, TexCoord0.xy);
}
我已经bmp
用调试器检查了,并使用了bmp.GetPixel(255,0)
(就在那棵树苗的上方,在黑色区域),它又回来了(0,0,0,0)
。文档说0 是完全透明的,所以......我一定在 OpenGL 方面做错了什么。但是什么?
渲染功能
protected override void OnRenderFrame(FrameEventArgs e)
{
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
_blockInstanceBuffer.Bind();
_blockIndexBuffer.Bind();
GL.DrawElementsInstancedBaseVertex(BeginMode.TriangleStrip, Data.FaceIndices.Length, DrawElementsType.UnsignedInt, IntPtr.Zero, _blockCount, 0);
SwapBuffers();
}