Opentk/Source/Examples/OpenGL/1.x/Picking.rtf

20 lines
1.3 KiB
Plaintext
Raw Normal View History

2010-10-02 18:52:34 +00:00
{\rtf1\ansi\ansicpg1253\deff0{\fonttbl{\f0\fnil\fcharset0 Arial;}}
{\colortbl ;\red163\green21\blue21;}
{\*\generator Msftedit 5.41.21.2509;}\viewkind4\uc1\pard\cf1\lang1033\b\fs28 Introduction\b0\fs22\par
\par
This sample demonstrates a way to select 3d objects from a scene using the mouse. In OpenGL nomenclature, this process is called "picking".\par
\par
\b\fs28 Controls\par
\b0\fs22\par
Press Esc or click the close button to exit.\par
The mouse pointer picks items automatically. Move the mouse to pick a different item.\par
\par
\b\fs28 Implementation\par
\b0\fs22\par
Every object in the scene is assigned a unique id by "coloring" all of its vertices with the same color. The color is generated by encoding the Int32 id into a 4-byte Rgba value.\par
\par
A first rendering pass clears the screen to Int32.MaxValue, disables all textures and shaders and renders the scene using the aforementioned coloring scheme. As soon as this rendering is complete, we use GL.ReadPixels() to retrieve the pixel below the mouse cursor. By reversing the encoding process, we convert the Rgba value of the pixel back into the unique Int32 id.\par
\par
A second rendering pass clears the screen once more and proceeds to render the scene normally (using all necessary textures and shaders). The user never sees the results of the first rendering pass!\par
}