I am trying to figure out how to extract an RGB value from a selected pixel. Each time I click, it gives me a value of 0, although I click on a colored triangle.
void mouse(int button, int state, int x, int y) {
if(state == GLUT_DOWN) {
float mx = p2w_x(x);
float my = p2w_y(y);
float rgb[3];
glReadPixels(mx, my, 1, 1, GL_RGB, GL_FLOAT, rgb);
std::cout << rgb[0] << std::endl;
}
}
source
share