2

hi guys i am in trouble with add picking object in a JOGL project. i know that this could be done with pick buffer.. but i can't find examples anyone?

nkint
  • 11,513
  • 31
  • 103
  • 174

1 Answers1

3

In general, as you are probably aware, JOGL code translates directly from any other OpenGL examples you might see on the web.

GL_SELECT based picking seems to be very much out of favour these days; deprecated in the spec and poorly implemented by drivers.

Alternatives you can use are:

  • Rendering each object with a unique color (and all lighting / fog etc disabled) so you can determine which object the mouse is over via glReadPixels. (Clearing buffers after the picking stage so that you can then render your normal graphics). This approach is explained by the top rated answer in OpenGL GL_SELECT or manual collision detection? for example.

  • Ray-casting into your geometry (see the selection FAQ link below). This also means that you don't have to have an active gl context in the thread you call the code from, fwiw.

I've used both of these methods in the same application, currently having good results with the latter, but since most of the objects in that application are spheres it is a lot cheaper than it might be with arbitrary models.

http://www.opengl.org/resources/faq/technical/selection.htm

Community
  • 1
  • 1
PeterT
  • 1,454
  • 1
  • 12
  • 22
  • by the way i perform picking in a MouseListener so i don't have a gl context aviable directly so i'll try geometric ray casting – nkint Dec 21 '10 at 19:02
  • You may be advised not to do too much significant work in the mouse listener itself; what you can do instead is store enough information about the mouse event that it can then be processed in the next display(). That way, you could use either of the approaches I mentioned. Sorry for not giving working code; I think you can find this stuff elsewhere (although I'm sure it took me a bit of effort to get this working I admit). Oh well, it's all character building. Good luck :) p.s. gluUnproject is your friend. – PeterT Dec 22 '10 at 00:12
  • hei, thanks very much. ok, gluUnproject to get points in world coordinates, and then the ray. then find distance between ray and point to check. but, the ray is the line between two point: first point - eye's camera coordinate, gluUnproject(width/2, height/2, 0) - and mouse on near plane, gluUnproject(mouseX, mouseY, 1) with 1 as the near plane declared as3° argument of gluPerspective. it works only for points on z=1.. i think i don't get the point – nkint Dec 23 '10 at 00:07
  • your ray is between unprojected mouse coordinates on the near and far clipping planes. See http://www.gamedev.net/community/forums/topic.asp?topic_id=270987 (first link on google for 'gluunproject ray') – PeterT Dec 24 '10 at 12:49