Possible Duplicate:
Glut Mouse Coordinates
Let’s say that I have a window of 600×600.
When I receive mouse events I don’t know what’s the real position of the mouse, in OpenGL I use this to draw points:
(-0.5,0.5) | (0.5,0.5)
|
--------(0,0)-------
|
|
(-0.5,-0.5) | (0.5,-0.5)
But when I receive GLUT mouse events depending on the size of the window I get different coordinates.I want a relative (to the window) coordinate system.How do I get this?
I am pretty sure glut gives you the mouse coordinates in window space (i.e. if the window is 800×600 and the mouse position is in the middle, it will give you x: 400, y: 300), so if you want to bring that to the opengl space you posted above, you would do the following:
so a generic version would look something like this: