From: Simon Wittber <simonwittber@gm...> - 2005-07-31 03:14:27
I'm trying to use glRenderMode(GL_SELECT) to implement picking. The
problem is, almost all picking examples deal with 3D projection
(gluPerspective), whereas I am using glOrtho, so I suspect I need to
do something different.
The below code doesn't work, it accumulates hits in the select buffer,
but they are not the hits I expect. Any pointers on where I might be
Also, is there a simple way to get OpenGL to render a small box on the
screen which shows exactly which region is being picked?
Thanks for any help...=20
def pick(self, position):
viewport =3D glGetIntegerv(GL_VIEWPORT)
n_w,n_h =3D display._screen.dimensions
for index, i in enumerate(self.items):
items =3D 
for hit in glRenderMode(GL_RENDER):
items =3D items + [self.items[i] for i in hit]
From: Mike C. Fletcher <mcfletch@ro...> - 2005-08-01 17:55:09
Simon Wittber wrote:
>I'm trying to use glRenderMode(GL_SELECT) to implement picking. The
>problem is, almost all picking examples deal with 3D projection
>(gluPerspective), whereas I am using glOrtho, so I suspect I need to
>do something different.
I don't actually use glOrtho, but I'll try to help...
>The below code doesn't work, it accumulates hits in the select buffer,
>but they are not the hits I expect. Any pointers on where I might be
From the docs for gluPickMatrix:
The matrix created by gluPickMatrix is multiplied by the current
matrix just as if glMultMatrix is called with the generated matrix.
To effectively use the generated pick matrix for picking, first call
glLoadIdentity to load an identity matrix onto the perspective
matrix stack. Then call gluPickMatrix, and finally, call a command
(such as gluPerspective) to multiply the perspective matrix by the
which suggests you want the gluOrtho call *after* the gluPickMatrix
call. I don't actually recall reversing the order in *my* code, but
then I haven't written code of this type in a long while.
>Also, is there a simple way to get OpenGL to render a small box on the
>screen which shows exactly which region is being picked?
You are creating a rectangular prism centred around the pick location.
So, do 8 gluUnProjects, one for each corner of the prism, with the near
face having winz of 0.0 and the far face having winz of 1.0. That
should give you a rectangle in model-space coordinates that you can
render (if I'm working through the logic correctly).
btw, you might want to check around and see if bitmap operations where
the bitmap position is outside of the picking matrix actually register
with a selection buffer (i.e. they don't draw if the bitmap position is
out-of-frustum, do they select when outside the picking frustum?)
> viewport = glGetIntegerv(GL_VIEWPORT)
> n_w,n_h = display._screen.dimensions
> display._screen.blit(i.item, i.position)
Mike C. Fletcher
Designer, VR Plumber, Coder