I am trying to figure out how to extract the RGB value from the pixel chosen. Every time I click though, it gives me a value of 0, even though I am clicking on a colored triangle.
void mouse(int button, int state, int x, int y) {
if(state == GLUT_DOWN) {
float mx = p2w_x(x); // pixel to world coordinates
float my = p2w_y(y);
float rgb[3];
glReadPixels(mx, my, 1, 1, GL_RGB, GL_FLOAT, rgb);
std::cout << rgb[0] << std::endl; // prints 0 for red always
}
}