Saturday 13 April 2013

iOS: OpenGL ES: implementing color picking

Color picking is a method to pick an object by rendering different objects with different color and reading pixel at the picking point.

To implement color picking for OpenGL ES on iOS, you need to make two changes:

1. in your touch handler, record the location of the touch and convert it to OpenGL window coordinates.

2. in your renderer, add a special rendering pass before your regular rendering pass. In this special rendering pass, clean the scene,  disable lighting and rendering each object with different color, then read the pixel at the saved picking position and convert it to object id. After that, clean the scene and render again with your normal rendering pass. Since the result of the special rendering pass is overwritten by the normal render pass, the user never sees it.

1 comment:

  1. hi Sam can i get any working sample code on this picking that u have explained above?I m new to opengl and hoping a working model will help me to implement this same. my e-mail address is this : 409347461@qq.com

    ReplyDelete