GDI Coordinate system

I know this question may be beneath most people but pls help.

In GDI the y value goes from top to bottom, OpenGL however goes from bottom to top. Also OpenGl’s origin is nicely placed in the centre of its coordinate system unlike GDI which has it in the top left corner. I am mapping my mouse position to the open gl position using gluProject.

My problem is that when i do this i am getting projected coords from the GL scene that are negative in the x and y directions in some cases. This leads me to believe, as GDI cannot have negative x and y that when the projection occurs it maps the x and y of the 3d objects with the assumption that the origin is at the centre of the window.

Can someone please help me to get my mouse position and the projected position to line up? The SetOriginEx function wont work for some reason so i can’t get the origin at the centre. Any ideas (a) why it isn’t working? (b) how to get the GDI system to make the y value increase upwards

Hope that makes sense

Are you able to visit
OpenGL tutorials on this site include the Camera Control By Mouse tutorial. It’s work.

The WM_MOUSEMOVE funtion always gives window coordinates in pixels, so SetWindowOrg etc. is useless unless you don’t call DPtoLP in the device context in which you set it.

This code should work though it’s not very exact.

int x = cursor_x;
int y = window_height- 1 -cursor_y
x = x - window_width/2;
y = y - window_height/2;

Where x and y form a coordinate system that has it’s center (nearly) at the center of the window. It is up to you to scale them appropriately afterwards. Use floats and typecasts to increase the accuracy, as you will most likely want the end-coordinates in floats rather than in ints…

[This message has been edited by Michael Steinberg (edited 03-05-2002).]