0

I want to change a single pixel of the bound texture.

I know i could have a 1x1 bitmap, and get the bitmap data of that, and then pass that in:

GL.TexSubImage2D(TextureTarget.Texture2D, 0, pixel.X, pixels.Y, 1, 1, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, bmpData.scan0);

However that seems ridiculously complicated for such a simple task of modifying one pixel. Is there a simpler way of doing this?

1 Answer 1

2

Is there a simpler way of doing this?

No. At least, not as far as OpenGL is concerned.

In general, people don't want to change one texel. If they're doing uploads, its because they want to update an entire region of texture data. And CPU->GPU DMA operations are designed around that fact.

As for the OpenTK part (creating bitmaps, locking, etc), you don't have to create a bitmap. You can use one of the TexSubImage2D overloads to pass a C# array.

3
  • Ok, cool thanks. I had totally overlooked the fact that i could pass arrays, that should make things easier.
    – Joel
    Sep 5, 2012 at 14:44
  • Oh wait, having an issue my attempt to make a pixel red failed. The pixel became transparent. GL.TexSubImage2D(TextureTarget.Texture2D, 0, X, Y, 1, 1, OpenTK.Graphics.OpenGL.PixelFormat.Rgba, PixelType.UnsignedInt, new uint[]{0xFFFF0000});
    – Joel
    Sep 5, 2012 at 15:03
  • @Randomman159: That sounds like an interesting question. Maybe you should ask it by clicking the "Ask Question" button. Comments are for commenting, not asking questions. Sep 5, 2012 at 16:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.