I am currently working on a some sort of editor. The terrain of this editor is a map built out of tiles (squares).When i click my GLJPanel i sent a mouseevent because I want to check if I click on a tile.

So basicly I want to convert my X and Y mouse coordinate to Coordinate in the XZ plane (since Y axis is the one pointing up).

So far I tried to do this using glu.gluUnProject but i have no success doing so

During init methode of GLEventListener

1 2 3

this.viewport = IntBuffer.allocate(4); // Where The Viewport Values Will Be Storedthis.modelview = FloatBuffer.allocate(16); // Where The 16 Doubles Of The Modelview Matrix Are To Be Storedthis.projectionview = FloatBuffer.allocate(16); // Where The 16 Doubles Of The Projection Matrix Are To Be Stored

but you're using 2D, aren't you? It's easier to just do the math to find where your mouse is in the game world. This requires you to keep track of the transformations that you do, but it should still be faster than doing that many OpenGL calls.

Great that you got it working. Remember that calling glReadPixels forces the processor to wait for the graphics card to render the scene. It's a very good idea to read pixels of the last frame instead, or at least do the read at the beginning of the next frame before clearing it. You can also do it asynchronously, but I don't know exactly how to do that though.

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org