iPhone glReadPixels 问题

发布于 2024-10-01 13:20:24 字数 493 浏览 1 评论 0原文

我正在 Iphone 中使用 OPENGL ES 绘制 PIE 字符。现在我需要检查用户单击的饼图的颜色。当我单击任何饼图时,它有时返回正确的值,有时不正确,有时只返回 0,0,0。

'(void)handleTap:(UITapGestureRecognizer *)识别器{

CGPoint lPoint = [识别器locationOfTouch:0 inView:mGLView];

字节aPixel[4]; glPixelStorei(GL_PACK_ALIGNMENT, 1); glReadPixels( lPoint.x, lPoint.y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &aPixel[0] );

NSLog(@"%i",glGetError()); NSLog(@"POINT X = %f Y = %f %d %d %d",lPoint.x, lPoint.y, aPixel[0],aPixel[1],aPixel[2]);'

I am drawing a PIE char in Iphone, with OPENGL ES. Now I need to check the color of the pie where user clicked. When I click any pie, it sometimes returns correct values, and sometimes not correct, and sometimes just returning 0,0,0.

'(void) handleTap:(UITapGestureRecognizer *) recognizer{

CGPoint lPoint = [recognizer locationOfTouch:0 inView:mGLView];

Byte aPixel[4];
glPixelStorei(GL_PACK_ALIGNMENT, 1);
glReadPixels( lPoint.x, lPoint.y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &aPixel[0] );

NSLog(@"%i",glGetError());
NSLog(@"POINT X = %f Y = %f %d %d %d",lPoint.x, lPoint.y, aPixel[0],aPixel[1],aPixel[2]);'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

橘虞初梦 2024-10-08 13:20:24

在 OpenGL 中,(0, 0) 是左下角像素。在 iOS 中,它是左上角的像素。所以你是从错误的位置阅读的。我想你想在调用 locationOfTouch:inView 之后添加:

lPoint.y = mGLView.bounds.height - lPoint.y;

In OpenGL, (0, 0) is the bottom left pixel. In iOS it's the top left pixel. So you're reading from the wrong location. I'd imagine you want to add, after the call to locationOfTouch:inView:

lPoint.y = mGLView.bounds.height - lPoint.y;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文