[英]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? 我试图使用glReadPixels实现一个简单的选择功能,但是当我单击一种颜色的对象时,是否会根据单击该对象的位置而获得不同的值? 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 ); glGetIntegerv(GL_VIEWPORT,_ viewport);
point.y = (float) _viewport[3] - point.y; point.y =(float) _viewport [3]-point.y;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.