Search code examples
c#opengltexturesopentk

OpenGL/TK Modify change single pixel of image


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?


Solution

  • 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.