iPhone OpenGL ES: glReadPixels not working
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)__vi开发者_如何学Cewport[3] - point.y;
glGetIntegerv( GL_VIEWPORT, _viewport );
point.y = (float)_viewport[3] - point.y;
精彩评论