这是我向OpenGL提供Bitmaps的方式。(C#)
我找到了一个关于数据应该如何组织的描述在这里,我理解为图像应该是垂直排列的,并且可能会翻转或其他操作。
结果是两个图像以大致相等的比例合并。如果我把
我本来期望这个参数是提供的图像的Z轴。或者如果我使用整数,则为提供的图像数组的索引。
编辑:它是索引,但被投影到0到1的范围上,就像x、y坐标一样。
我哪里做错了?
我向OpenGL提供的内容(顺序):
链接:
结果:
链接:
编辑:正如Rabbid76所解释的那样,解决方案是在调用
public static int Generate3DTexture( string[] names ) // file paths
{
//basically merging the images into one vertical column of images
MagickImageCollection allimages = new MagickImageCollection();
foreach (string eachname in names)
allimages.Add(new MagickImage(eachname));
MagickImage template = new MagickImage(MagickColor.FromRgba(0, 0, 0, 0), MasterSize.Width, MasterSize.Height * names.Length);
Point drawpnt = new Point(0, 0);
foreach (MagickImage each in allimages)
{
template.Composite(each, drawpnt.X, drawpnt.Y, CompositeOperator.Overlay);
drawpnt.Y += each.Height;
}
Bitmap merged = template.ToBitmap();
//saving the bitmap here is confirmed to stack them vertically
BitmapData thedata = merged.LockBits(new Rectangle(new Point(0, 0), merged.Size), ImageLockMode.ReadOnly, WfPixelFormat.Format32bppArgb);
int texId = GL.GenTexture();
GL.BindTexture(TextureTarget.Texture3D, texId);
GL.TexImage3D(TextureTarget.Texture3D, 0, PixelInternalFormat.Rgba, MasterSize.Width, MasterSize.Height, names.Length, 0, GlPixelFormat.Bgra, PixelType.UnsignedByte, thedata.Scan0);
GL.GenerateMipmap(GenerateMipmapTarget.Texture3D);
GL.BindTexture(TextureTarget.Texture3D, 0);
merged.UnlockBits(thedata);
return texId;
}
我找到了一个关于数据应该如何组织的描述在这里,我理解为图像应该是垂直排列的,并且可能会翻转或其他操作。
因此,在我的测试中,我使用了2张图片,在片段着色器中,我这样应用纹理:
void main()
{
outputColor = texture3D(ThreeDTexture,vec3(texcoord.x, 1.0 - texcoord.y, 0));
}
结果是两个图像以大致相等的比例合并。如果我把
vec3.z
参数设为0.5
,那就是我所期望的。所以我用三张图片试了一下。它给出了前两张图片和最后两张图片的50-50组合(?!?!?)。这是在不考虑我给vec3.z
赋的值的情况下的行为。我本来期望这个参数是提供的图像的Z轴。或者如果我使用整数,则为提供的图像数组的索引。
编辑:它是索引,但被投影到0到1的范围上,就像x、y坐标一样。
我哪里做错了?
我向OpenGL提供的内容(顺序):
链接:
![What I'm giving to OpenGL](https://istack.dev59.com/sY8Ui.webp)
链接:
![The result.](https://istack.dev59.com/NalrC.webp)
GL.TexImage3D
之后插入以下内容: GL.TexParameter(TextureTarget.Texture3D, TextureParameterName.TextureWrapS, (int)TextureParameterName.ClampToEdge);
GL.TexParameter(TextureTarget.Texture3D, TextureParameterName.TextureWrapT, (int)TextureParameterName.ClampToEdge);
GL.TexParameter(TextureTarget.Texture3D, TextureParameterName.TextureWrapR, (int)TextureParameterName.ClampToEdge);