Hey there,
I'm trying to get a single pixel value from a RenderTexture. The image is grayscale, so I really only need one of the channels. The current solution uses
uint8_t px = renderTex.getTexture().copyToImage().getPixel(x, y).r;
which, as you can imagine, is pretty damn slow - but at least it ensures that renderTex is initialized and looks like what I expect it to.
To speed it up I tried to use raw OpenGL (which I'm a total noob at, SFML has shielded me from that arcane knowledge for years) to get the pixel like so:
uint8_t px;
sf::Texture::bind(renderTex.getTexture());
glReadPixels(x, renderTex.getTexture().getSize().y - y, 1, 1, GL_RED, GL_UNSIGNED_BYTE, &px);
assert(glGetError() == GL_NO_ERROR);
Sadly, glReadPixels doesn't write to px at all. If I initialize it with some value, this value is never overwritten. The assertion is always true, so glReadPixels doesn't throw an error either.
What's wrong here? Any hint is appreciated.
Thanks,
Daerst