¿Por qué mi textura PNG no sale con transparencia?
La imagen inferior derecha debería tener un fondo transparente.
me carga PNG mi de Notch a través de estas funciones:
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);
}
Y mi fragmento de sombreado se ve así:
#version 330
in vec2 TexCoord0;
uniform sampler2D TexSampler;
void main()
{
gl_FragColor = texture2D(TexSampler, TexCoord0.xy);
}
He inspeccionado el bmp
con el depurador, y se utiliza bmp.GetPixel(255,0)
(justo encima de ese árbol joven, en el área negra) y vuelve (0,0,0,0)
. The docs say 0 es completamente transparente, entonces ... Debo estar haciendo algo mal en el lado OpenGL de las cosas. ¿Pero que?
función
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();
}
Ahhh Minecraft, no se puede escapar! – Zenexer
Esto parece un juego que vi una vez en alguna parte. – Ryan
Sí, creo que definitivamente lo estás cargando correctamente. Ese no es el problema. – Zenexer