我已经用这种方法加载了一个图像:
public static int LoadTexture(string file)
{
Bitmap bitmap = new Bitmap(file);
int tex;
GL.GenTextures(1, out tex);
GL.BindTexture(TextureTarget.Texture2D, tex);
System.Drawing.Imaging.BitmapData data = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height),
System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, data.Width, data.Height, 0,
OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, data.Scan0);
bitmap.UnlockBits(data);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat);
Console.WriteLine("[ImageDisplay] Loaded image: " + file);
return tex;
}
我需要修改此图像中的像素,所以我使用了这个:
GL.TexSubImage2D(TextureTarget.Texture2D, 0, X, Y, 1, 1, OpenTK.Graphics.OpenGL.PixelFormat.Rgb, PixelType.UnsignedInt, new uint[] { 0xFFFF0000 });
我的问题是只有非透明像素变为红色,透明像素根本没有变化。
我该如何解决这个问题?