iPhone OpenGL ES:glReadPixels 不工作
我尝试使用 glReadPixels 实现一个简单的拾取功能,但是当我单击 1 种颜色的对象时,我会根据单击该对象的位置获得不同的值?有没有特殊的灯光等?这是怎么回事?有时会返回全零。我关掉了所有东西(纹理等),但仍然没有快乐。
我认为这个函数返回您点击的像素的颜色?
- (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]);
}
更新:添加了这个来修复它:
glGetIntegerv( GL_VIEWPORT, __viewport );
point.y = (float)__viewport[3] - point.y;
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;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
glGetIntegerv( GL_VIEWPORT, _视口 );
point.y = (float)_viewport[3] - point.y;
glGetIntegerv( GL_VIEWPORT, _viewport );
point.y = (float)_viewport[3] - point.y;