Opengl 如何从渲染纹理中读取像素(颜色附件)

Opengl 如何从渲染纹理中读取像素(颜色附件),opengl,pixel,opentk,fbo,glreadpixels,Opengl,Pixel,Opentk,Fbo,Glreadpixels,我将颜色和位置纹理渲染到fbo中的colorattachment0和colorattachment1。颜色纹理正在绘制到立方体上以进行不同的渲染。不过我需要从位置纹理中读取,这是我发送给colorattachment1的。以下是我尝试过的: public float[] getUV() { float[] uv = new float[2]; var pixel = new float[4]; GL.ReadBuffer(ReadBufferMode.ColorAtta

我将颜色和位置纹理渲染到fbo中的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的鼠标坐标正确。

什么是“完全错误”呢?你得到了什么价值,你期望什么?不过,将数据作为无符号字节读回浮点数组可能不是您想要的。@derhass就是这样,我不知道我怎么会错过它。谢谢