From: Alban C. <aco...@wa...> - 2002-08-02 10:25:54
|
>Hi all, > >I've been playing with picking and started with the Red Books picking >example. (the one with a grid of different color squares and the square >changes color when you click it.) > >However, when I call the picking code, and use: > >hits =3D gl.glRenderMode(GL_RENDER); > >hits is always 0. I've searched the archives and no one else seems to >have this particular problem, so I must be doing something rather dumb. >I've included the two source files. Any help would be greatly >appreciated. > >--Mark Hi Mark, I personnaly had no problems implementing picking and it works perfectly, though I've had the same behaviour (hits return 0) when implementing the picking on quads. This is not a gl4java bug nor a MS JVM bug, but a general OpenGL problem. Strangely, OpenGL in ANY implementation is unable to pick quads in ortho mode. I assume this could be because picking implementation could be tightly dependant of the depth buffer, and the depth buffer could be somewhat limited/uncompatible in ortho mode.=20 To be able to pick quads (or any 2D elements), you have to implement color picking, as stated in the OpenGL faq http://www.opengl.org/developers/faqs/technical/selection.htm, section 20.010 I did it and it works perfectly, though the help on its implementation in the OpenGL faq is very uncomplete and confuse. The strategy is to draw your quads in an offscreen buffer that cannot be seen by the user, assigning each quad a unique color that you record as an integer value in an hashtable, associated with your quad name. (I personnaly took pure red, as an integer value between 0 and 255 wich allows me to have 256 unique colors. To be able to pick more objects, you can add a green and a blue value, allowing you to pick up to 16 Million objects). In order to avoid your color to be corrupted by openGL, you have to disable any component that might affect your color : gl.glDisable(gl.GL_BLEND); gl.glDisable(gl.GL_FOG); gl.glDisable(gl.GL_LIGHTING); gl.glDisable(gl.GL_TEXTURE_1D); gl.glDisable(gl.GL_TEXTURE_2D); gl.glDisable(gl.GL_TEXTURE_3D); gl.glShadeModel(gl.GL_FLAT); Whenever you perform a pick, you read the color of the pixel located under the mouse using glReadPixels(). Once you have the color, you can find out wich object it relates to by retrieving the name of the quad associated as a pair with the integer value of the color in your hashtable. But before implementing color picking, you should try drawing 3D objects with your current implementation (such as a cube, and not in ortho mode) and your picking should work fine with these. Regards, Alban Cousini=E9 |