Hi guys!
I’m an Italian developer and i’m beginner in the OpenGL world.
I use OpenTK in order to use OpenGL with C# language, but, I think, this is not the cause of my problem.
(I post the code in C#, but it is easy to see the corresponding command in c++)
I’ve a problem with the function glTexSubImage3D.
I define my texture 3d in this way:
GL.GenTextures(1, out _textureID);
GL.BindTexture(TextureTarget.Texture3D, _textureID);
GL.TexParameter(TextureTarget.Texture3D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
GL.TexParameter(TextureTarget.Texture3D, TextureParameterName.TextureMagFilter, (int)TextureMinFilter.Linear);
GL.TexParameter(TextureTarget.Texture3D, TextureParameterName.TextureWrapS,
(int)TextureWrapMode.ClampToBorder);
GL.TexParameter(TextureTarget.Texture3D, TextureParameterName.TextureWrapT,
(int)TextureWrapMode.ClampToBorder);
GL.TexParameter(TextureTarget.Texture3D, TextureParameterName.TextureWrapR,
(int)TextureWrapMode.ClampToBorder);
GL.TexImage3D<ushort>(TextureTarget.Texture3D, 0, PixelInternalFormat.Rgba16, _sizeX, _sizeY, _sizeZ, 0,
PixelFormat.Alpha, PixelType.UnsignedShort, _texelsObj);
var err = GL.GetError(); // --> NO ERROR
Up to this point everything ok, i render my texture 3d handling the alpha values in the glsl shader, defining the colors for each voxel.
Now, i want to change a “plane” of the texture, coloring it with a single colour.
I use the texSubImage3D function:
(_planeTexelsX,_planeTexelsY, _planeTexelsZ are filled of ushort.MaxValue )
GL.BindTexture(TextureTarget.Texture3D, _textureID);
GL.TexSubImage3D<ushort>(TextureTarget.Texture3D, 0, 0, 0, planeZ, _sizeX, _sizeY, 1, PixelFormat.Red,
PixelType.UnsignedShort, _planeTexelsZ);
This works, it make the plane, with z = planeZ, red.(for each x, y)
GL.BindTexture(TextureTarget.Texture3D, _textureID);
GL.TexSubImage3D<ushort>(TextureTarget.Texture3D, 0, 0, planY, 0, _sizeX, 1, _sizeZ,
PixelFormat.Green, PixelType.UnsignedShort, _planeTexelsY);
This works, it make the plane, with y = planeY, green.(for each z, x)
GL.BindTexture(TextureTarget.Texture3D, _textureID);
GL.TexSubImage3D<ushort>(TextureTarget.Texture3D, 0, planeX, 0, 0, 1, _sizeY, _sizeZ,
PixelFormat.Blue, PixelType.UnsignedShort, _planeTexelsX);
This should make the plane, with x = planeX, blue, but doesn’t work.
If i call the function
ushort[] pix = new ushort[_texels.Length];
GL.GetTexImage<ushort>(TextureTarget.Texture3D, 0, PixelFormat.Blue, PixelType.UnsignedShort, pix);
(that gives me the values of the texture3D) i see that the first values are correct but some values are wrong.
Any idea?
I can’t figure out why the first two cases works and the last doesn’t.
It is allowed defines the texture3D with internalPixelFormat rgba16, and defines the subTexture for red, green or blue component only?
(Sorry for the bad english, hope you can understand)
Thanks!