View Full Version : Getting the coordinates of what you've drawn

09-23-2010, 10:55 PM

I'm still discovering OpenGL, so sorry if I missed that part in the Big Red book! :)

For my application, I draw one 3D form 3 times. Each time, I use glOrtho to show an orthographic projection of the form. Now my problem is the following: is there a way to know what has been plotted in one of the 3 orthographic projections? My final goal would be to be able to add more stuff (such as text, lines, etc.) directly on the orthographic projection once it has been drawn.

So I imagined that by getting the coordinates of what is drawn after the glOrtho, I could just add stuff on it, but I can't seem to find how to do that. Another solution would be to add the stuff I want to add before applying glOrtho, but that wasn't my first intuition... would that be the way to go? And then, is there a way to compute myself where a point whose coordinates I know will be after I apply glOrtho to it?

Hope this is understandable and someone can point me in the right direction!


09-26-2010, 08:34 AM
You need to create an inverse matrix of the matrix you using to transform your co-ordinates from world into screen space. Then you transform your mouse position using the inverse matrix, which will switch the mouse screen position into world space. Also depending on which direction your Y axis points you might need to flip the Y position of the mouse to get the screen space co-ordinates as OpenGL sees them. It's a simple screenHeight-mouse.pos.y to do the flipping.

09-30-2010, 08:20 AM
Turns out that OpenGL has some stuff embedded (gluUnproject, selection, picking, etc.), so no need to do it by hand.