I'm toying with an implementation of the picking technique suggested here.
However it appears that this code will always return 4x zero, although the buffer was previously cleared with 4x 1f.
// after bind FBO, draw obj, while FBO is bound and readbuffer set to correct color attachment: Byte4 Pixel = new Byte4(); GL.ReadPixels<Byte4>(Mouse.X, FBO_height-Mouse.Y, 1, 1, PixelFormat.Rgba, PixelType.UnsignedByte, ref Pixel); uint SelectedTriangle = Pixel.ToUInt32();
this code does prove that there's neither a problem with the FBO nor the attachment:
// after bind FBO, draw obj, unbind FBO GL.Enable(EnableCap.Texture2D); GL.BindTexture(Target, ColorAttachment); Byte4 Tex = new Byte4[FBO_width * FBO_height]; GL.GetTexImage<Byte4>(Target, 0, PixelFormat.Rgba, PixelType.UnsignedByte, Tex); GL.BindTexture(Target, 0); GL.Disable(EnableCap.Texture2D); SelectedTriangle = Tex[(FBO_height-Mouse.Y)*FBO_width+Mouse.X].ToUInt32();
The later is a huge waste of memory (and prone to indexing out of array bounds) but it gives me the correct triangle index. GL.ReadPixels will never return any values besides zeros.
I've taken a look at svn and the ReadPixels pinning looks ok, besides that it should use "out" not "ref". Any ideas what's wrong with this?