0

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?

Joel
  • 1,580
  • 4
  • 20
  • 33

1 Answers1

3
OpenTK.Graphics.OpenGL.PixelFormat.Rgb, PixelType.UnsignedInt, new uint[] { 0xFFFF0000 }

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.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
  • Please reply :/ or someone else answer? This is correcting my use of the data parameter, but not solving this issue. Pixels that are not transparent are updated to red. Transparent pixels are still unchangeable. – Joel Sep 06 '12 at 09:34
  • Ok, i got it: GL.TexSubImage2D(TextureTarget.Texture2D, 0, x, y, 1, 1, OpenTK.Graphics.OpenGL.PixelFormat.Rgba, PixelType.UnsignedByte, new byte[] { color.R, color.G, color.B, 255 }); thanks – Joel Sep 09 '12 at 05:37