0

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]);'

Oleg Danu
  • 4,149
  • 4
  • 29
  • 47

1 Answers1

1

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;
Tommy
  • 99,986
  • 12
  • 185
  • 204
  • Ok, I have changed according to what you said, but it still not the same :( – Oleg Danu Nov 15 '10 at 07:09
  • There's no possibility you're running on a Retina Display is there? If so then be careful because locationOfTouch:inVieW: returns the location in points, not in pixels. Otherwise I suggest you log values under the finger as it moves and see if you can figure out where in the image the pixels are actually being read from; it'll be some mismatch between iOS coordinates and OpenGL coordinates somewhere. – Tommy Nov 15 '10 at 11:49