c++ - Finding Pixel Color -


i trying figure out how extract rgb value pixel chosen. every time click though, gives me value of 0, though clicking on colored triangle.

void mouse(int button, int state, int x, int y) {     if(state == glut_down) {         float mx = p2w_x(x); // pixel world coordinates         float = p2w_y(y);         float rgb[3];         glreadpixels(mx, my, 1, 1, gl_rgb, gl_float, rgb);         std::cout << rgb[0] << std::endl; // prints 0 red     } } 

i don't think should convert pixel coordinates world coordinates. don't know gl, looks wrong me. pixel coordinates mouse right? , want pixel color value, from framebuffer.

maybe use integer type color value, gl_unsigned_byte , array of unsigned char rgb[3]; instead. , use gl_rgb8 format, instead of plain gl_rgb.

also see how set pixel format (store) of frame buffer. affect subsequent glreadpixels calls.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -