Re: Noob question - Color pick selection - Buffer creation

Ian Mallett <[email protected]> Thu, 10 Mar 2016 13:43:39 -0700
Newsgroups gmane.comp.python.opengl.user
Message-ID <CAG4NV=tHviLK2OiNLwKULHhjN6N1odo+foOzKUmzr=FqZSkn+w@mail.gmail.com>
--===============5216736080374444016==
Content-Type: multipart/alternative; boundary=001a1147a4766baaf8052db7df09

--001a1147a4766baaf8052db7df09
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

On Thu, Mar 10, 2016 at 4:46 AM, Jorge <[email protected]> wrote:

> However I have been looking for a way to pick 3d objects. I have seen tha=
t
> the way is creating an additional buffer that is not showed and select fr=
om
> 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.
>
=E2=80=8BThere 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

--001a1147a4766baaf8052db7df09
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div class=3D"gmail_default" style=3D"font-family:times ne=
w roman,serif"><span style=3D"font-family:arial,sans-serif">On Thu, Mar 10,=
 2016 at 4:46 AM, Jorge </span><span dir=3D"ltr" style=3D"font-family:arial=
,sans-serif">&lt;<a href=3D"mailto:[email protected]" target=3D"_blank">g=
[email protected]</a>&gt;</span><span style=3D"font-family:arial,sans-seri=
f"> wrote:</span><br></div><div class=3D"gmail_extra"><div class=3D"gmail_q=
uote"><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-l=
eft:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div><div><div><div><=
div><div>However I have been looking for a way to pick 3d objects. I have s=
een that the way is creating an additional buffer that is not showed and se=
lect from this buffer based on a color assigned to each object. This is the=
 theory however I can&#39;t manage to create or find a basic example.=C2=A0=
<br></div></div></div></div></div></div></div></blockquote><div><div class=
=3D"gmail_default" style=3D"font-family:&#39;times new roman&#39;,serif">=
=E2=80=8BThere are several ways. Modern game engines just raytrace that one=
 pixel on the CPU to find out what you&#39;re over. This is the &quot;right=
&quot; solution.</div><div class=3D"gmail_default" style=3D"font-family:&#3=
9;times new roman&#39;,serif"><br></div><div class=3D"gmail_default" style=
=3D"font-family:&#39;times new roman&#39;,serif">For a GPU solution, the ba=
sic 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--&quot;picking buffer&quot;, and so on--but fundament=
ally they don&#39;t do anything more complex than this.</div><div class=3D"=
gmail_default" style=3D"font-family:&#39;times new roman&#39;,serif"><br></=
div><div class=3D"gmail_default" style=3D"font-family:&#39;times new roman&=
#39;,serif">But since you are really new to OpenGL, there&#39;s an even sim=
pler 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 le=
ss than the previous value, then you hit the object you just rendered. Repe=
at until you&#39;ve drawn your whole frame. This will be pretty slow, but i=
t has the advantage that you don&#39;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=
.</div></div><div class=3D"gmail_default" style=3D"font-family:&#39;times n=
ew roman&#39;,serif"><br></div><div class=3D"gmail_default" style=3D"font-f=
amily:&#39;times new roman&#39;,serif">Ian</div></div></div></div>

--001a1147a4766baaf8052db7df09--


--===============5216736080374444016==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

------------------------------------------------------------------------------
Transform Data into Opportunity.
Accelerate data analysis in your applications with
Intel Data Analytics Acceleration Library.
Click to learn more.
http://pubads.g.doubleclick.net/gampad/clk?id=278785111&iu=/4140
--===============5216736080374444016==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
PyOpenGL Homepage
http://pyopengl.sourceforge.net
_______________________________________________
PyOpenGL-Users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pyopengl-users

--===============5216736080374444016==--