我在colo中将颜色和位置纹理渲染到colorattachment0和colorattachment1。正在将颜色纹理绘制到立方体上以进行不同的渲染。我需要从位置纹理读取,我发送到colorattachment1。以下是我的尝试:
public float[] getUV()
{
float[] uv = new float[2];
var pixel = new float[4];
GL.ReadBuffer(ReadBufferMode.ColorAttachment1);
GL.ReadPixels((int)curPoint.X, (int)curPoint.Y, 1, 1, OpenTK.Graphics.OpenGL.PixelFormat.Rgba, PixelType.UnsignedByte, pixel);
uv[0] = pixel[0];
uv[1] = pixel[1];
return uv;
}
我在mousedown事件上调用getUV。以下是我创建fbo的方法:
GL.Ext.GenFramebuffers(1, out fboHandle);
GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, fboHandle);
GL.Ext.FramebufferTexture2D(FramebufferTarget.FramebufferExt, FramebufferAttachment.ColorAttachment0Ext, TextureTarget.Texture2D, colorTexture, 0);
GL.Ext.FramebufferTexture2D(FramebufferTarget.FramebufferExt, FramebufferAttachment.ColorAttachment1Ext, TextureTarget.Texture2D, uvTexture, 0);
GL.Ext.FramebufferTexture2D(FramebufferTarget.FramebufferExt, FramebufferAttachment.DepthAttachmentExt, TextureTarget.Texture2D, depthBufferTexture, 0);
从getUV()返回的值是完全错误的,我想我错过了一步。我已经验证了ColorAttachment1正确渲染,并且我发送给ReadPixels的鼠标坐标是正确的。