I have loaded in an image with this method:
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;
}
I need to modify pixels within this image, so i have used this:
GL.TexSubImage2D(TextureTarget.Texture2D, 0, X, Y, 1, 1, OpenTK.Graphics.OpenGL.PixelFormat.Rgb, PixelType.UnsignedInt, new uint[] { 0xFFFF0000 });
My problem, is that only non-transparent pixels change to red, the transparent pixels do not change at all.
How could i fix this?
The pixel transfer format you state is
GL_RGB. That means 3 components: red, green, and blue, in that order.The pixel transfer type is
GL_UNSIGNED_INT, which means that each component is an unsigned integer. Thus, you are expected to provide an array of 3 unsigned integers per pixel.If you want each component to be an unsigned byte, then you should use that as your type. And your array should be an array of unsigned bytes.