I'm drawing points inside a square. Coordinates range from -0.5 to 0.5. The color of the points depend on his position.
Fragment shader does this:
gl_FragColor = vec4(v_position.x+0.5, v_position.y+0.5, v_position.z+0.5, 1.0);
After rendering in backbuffer I read the buffer:
byte pixel = new byte; GL.ReadPixels(x, _glControl.Height - y, 1, 1, PixelFormat.Rgba, PixelType.UnsignedByte, pixel);
Vector4 point = new Vector4(); point.X = (((float)pixel)/255)-0.5f; point.Y = (((float)pixel)/255)-0.5f; point.Z = (((float)pixel)/255)-0.5f;
I want to get back the exact position of the point I clicked on.
The output is correct for position values like 0.1 and 0.2.
But for coordinate 0.15 I get 0.1509804. For 0.03 I get 03333334.
So the precision of this method is not very precies. Does anyone have an idea why this is the case? PixelFormat ? PixelType?
I expect the color on the buffer to be exactly what I specified in the shader. And I expect to read out the exact color from the buffer.
This should be possible I think. Or is OpenGL not precise enough with colors?