I would like to read with glReadPixels() the value from the colorbuffer, which I previously wrote in the Fragmentshader via gl_FragColor. This works on average 10 times, then an erroneous value (1 = 255) occurs.
#version 420
uniform vec2 screenXy;
uniform vec2 screenSize;
out highp vec4 fragColor;
void main(void) {
if((int(gl_FragCoord.x) == int(screenXy.x)) && ((int(screenSize.y - 1) - int(gl_FragCoord.y)) == int(screenXy.y))) {
fragColor.r = 0.5; // any value
} else {
fragColor = vec4(1, 1, 1, 1.0);
}
I submit the mouse xy coordinates to the fragementshader (screenXy). If the clicked pixel is in the row, I write a value (e.g 0.5) in the color buffer. Now I observe that sometimes the value is 1 (= 255) instead of 0.5 (=128).
GLfloat zc[4]; // from color buffer
m_func->glReadPixels(xy.x(), (m_pFbo->height() - 1) - xy.y(), 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, z);
qDebug() << "z0 " << z[0];
I see this behavior on win10 and android. Does anyone has an idea what i'm doing wrong?