I trying to implement a simple picking function using glReadPixels however when I click on an object that is 1 colour, I get different values back depending on where I clicked on that object? There not special lighting etc? Whats going on? Sometimes all zeros are returned. I turned everything off (textures etc) but still no joy.
I thought this functions returns the colour of the pixel you click on?
- (void)getPixelColour:(CGPoint)point {
Byte pixelColour[4];
glReadPixels(point.x, point.y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &pixelColour);
NSLog(@"%d %d %d", pixelColour[0], pixelColour[1], pixelColour[2]);
}
Update: added this to fix it:
glGetIntegerv( GL_VIEWPORT, __viewport );
point.y = (float)__viewport[3] - point.y;
glGetIntegerv( GL_VIEWPORT, _ viewport );
point.y = (float) _viewport[3] - point.y;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.