Continuation of this question I asked. In that question I show how I give 3 textures to opengl and render one of them. I'm trying to edit one of these textures without replacing them all using this code:
public void Replace( string name, int index)
{
Bitmap bmp = new Bitmap(name); //assumed to be MasterSize
BitmapData thedata = bmp.LockBits(new Rectangle(new Point(0, 0), MasterSize), ImageLockMode.ReadOnly, WfPixelFormat.Format32bppArgb);
GL.BindTexture(TextureTarget.Texture3D, Id);
GL.TexSubImage3D(TextureTarget.Texture3D, 0, 0, 0, 0, MasterSize.Width, MasterSize.Height, index, GlPixelFormat.Bgra, PixelType.UnsignedByte, thedata.Scan0);
GL.BindTexture(TextureTarget.Texture3D, 0);
bmp.UnlockBits(thedata);
}
MasterSize is the same Size
as it is in the previous question and Id is the int texId
from the previous question.
When I render the 0th texture on the shader (as shown previously) and Replace
index = 0
nothing changes. However when I Replace
with index = 1
and render the 0th, it does what I expected the index = 0
to do.
Despite having 3 textures, I get a memory corruption error when index = 2
(but not for absurd values like -4 and 12).
System.AccessViolationException: 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.'
I can access all 3 textures by using 0
, 0.5
, and 1
for the texture's Z on the shader, so I know they're there.
The 8th parameter of TexSubImage3D is an int, so it's not expecting a float range 0 to 1.
What am I doing wrong?