is available in legacy OpenGL (without shader), but it is rather complicated and unintuitive. ◼ Write labels to off-screen buffer ◼ If shader program is available, it is more intuitive. ◼ Draw a label (i.e., an index to identify the object) on screen. ◼ It’s easy! You can do it just by not calling “glfwSwapBuffers.” ◼ If target buffer is off-screen buffer, it does not affect visible objects! Computer Graphics Course @Waseda University 2
(by mouse event callback). 2. Write object index as pixel color (to off-screen buffer). 3. Pick up pixel values using glReadPixels. 4. Check pixel value and identify selected object. Computer Graphics Course @Waseda University 3
changed. Perform coordinate transformation. ◼ Fragment shader Computer Graphics Course @Waseda University Transform “selectID” to floating point number in [0, 1] when ID is positive. 5 Note: float outputs are automatically converted to UINT8 by multiplying 255.
X coordinate of upper left pixel of buffer area to be read. ◼ 2nd: Y coordinate of upper left pixel of buffer area to be read. ◼ 3rd: Width of buffer area to be read. ◼ 4th: Height of buffer area to be read. ◼ 5th: Color format of buffer data (typically GL_RGBA). ◼ 6th: Scalar type of buffer data (typically GL_UNSIGNED_BYTE). ◼ 7th: Pointer to data array in which the read data is stored. Computer Graphics Course @Waseda University 6
buffer, and pick up its value at clicked pixel. Problem ◼ Data transfer between RAM and GPU memory is time consuming. ◼ Reading entire buffer is not efficient. Computer Graphics Course @Waseda University Be careful that Y coordinate is inversed! 7
Then, highlight only the selected face. When non-cube region is clicked, highlight entire cube. ◼ You should draw only a single cube (do not have to draw multiple cubes as in the example). Computer Graphics Course @Waseda University 11