from mouse coords to opengl?

hi how can i traslate from mouse coords to opengl ones? i want to know if my mouse is over a graphic so i can perform some actions i know how to do all the event checking etc but i dont understand how i should translate the coords so i can check them!

im using the normal windows pointer though not an internal one in my game

whats the best efficent and fastest way of doing this?

if you’re asking what i think you’re asking you want

screenx = mousex + glutGet( GLUT_WINDOW_X )
screeny = mousey + glutGet( GLUT_WINDOW_Y )


read back the depth value (glReadPixels) of the pixel under the mouse and use this value and the mouse positions in gluunproject to get the world position of the mouse.

You can also code your own function. Let’s say you work with x/y-coords in rage from -1 to 1 wit 0/0 in the center of your screen:

private void world_coord(int x,int y,Vector2d p) {
if (width > height) {
p.x = (2.0x-width)/height;
p.y = 1.0-2.0
y/(double) height;
} else {
p.x = 2.0x/(double) width-1.0;
p.y = (height-2.0

You convert by giving x,y and a Vector2d, which will contain the converted coords afterwards.

is the double float precision needed for this?
i thought it should only be used on real critical parts like cientific physics and the so not for just converting something simple like this.

anyways thanks im going to check all this and tell you about it so if i dont want to use glu or glut i can always do my own like on your example ?? what would be better ??