glReadPixels draw issue

Started by
0 comments, last by O-san 14 years, 1 month ago
I'm working on an Android project and having trouble with glReadPixels. In order to determine what the user is clicking on, I am giving each object a unique color and redrawing the scene. I use glReadPixels to get the pixel color where they touched, and then I'm able to use that color and figure out what object they touched. The (simplified) flow of the draw function looks something like this:
draw()
{
  if (bScreenWasTouched)
  {
    drawSceneWithTouchColors();
    glReadPixels();//read pixel they touched
    glClear(color | depth);
  }

  drawSceneAsUsual();
}
The problem is that on some android devices the screen isn't getting cleared when glClear is called (you can see the results of drawSceneWithTouchColors when I would expect it to be gone). If I remove only the glReadPixels call, then everything works correctly. This really confuses me since I'm still doing all the drawSceneWithTouchColors drawing. At first I thought maybe it was a bug with the device's opengl implementation, but I am seeing this on another phone as well (other phones work fine), which makes me think I'm doing something wrong and most phones are handling my error more gracefully. Any ideas? I'm kinda stumped on this..
scottrick49
Advertisement
Sorry I can't help you with your particular glReadPixels problem. But I would suggest you use a ray-triangle test against the world objects instead. That way you don't need to render your scene twice. glReadPixels are known to be slow too, I'd avoid it for that reason alone (I guess reading only a few pixels are quite fast though).

Paul Bourke has some nice information regarding geometry releated problems.

GL

This topic is closed to new replies.

Advertisement