Re: [PyOpenGL-Users] Noob question - Color pick selection - Buffer creation
Brought to you by:
mcfletch
From: Ian M. <ia...@ge...> - 2016-03-10 20:44:00
|
On Thu, Mar 10, 2016 at 4:46 AM, Jorge <gus...@gm...> wrote: > However I have been looking for a way to pick 3d objects. I have seen that > the way is creating an additional buffer that is not showed and select from > this buffer based on a color assigned to each object. This is the theory > however I can't manage to create or find a basic example. > There are several ways. Modern game engines just raytrace that one pixel on the CPU to find out what you're over. This is the "right" solution. For a GPU solution, the basic idea is to render everything a different color, and then read the color under your pixel. The basic idea here is to use a separate pass. There are fancy names for this--"picking buffer", and so on--but fundamentally they don't do anything more complex than this. But since you are really new to OpenGL, there's an even simpler way. When you begin the frame, your depth value has been cleared to 1.0. Now render an object and check the depth again. If the depth value is less than the previous value, then you hit the object you just rendered. Repeat until you've drawn your whole frame. This will be pretty slow, but it has the advantage that you don't need to try to find non-overlapping colors or worry about color precision issues or passing the right thing to your shaders. glReadPixels is the command you want for looking up the depth. Ian |