OpenGL coordinate system

Hello guys,

Can someone explain me how the OpenGL coordinate system work ? I mean, I have windows coordiantes when I get WM_LBUTTONDOWN handle message, let’s say X = 100 and Y = 150, why when I use gluUnproject function, I have a smaller value for the X and Y coordinates ?

Thank you for the moment

Best regards

Kurt

One reason for your so called “incorrect” values can be that Windows and OpenGL is using different types of window coordinates. In Windows, the Y-axis is going from top to bottom of the window, but in OpenGL, the Y-axis is going from bottom to top. You need to change the Y-coordinate to get OpenGL-coordinates.

opengl_y = window_height - windows_y;

Ok Bob,

I’m making this transformation, but also if I made the y coordinate transformation I have the X,Y OpenGL value smaller then the GDI coordinates, is it normal ?

Thank you for the moment

Best regards

Kurt

To do a gluUnproject you need a third coordinate for OpenGL, the z-Buffer value on the x and y windows coordinates. Then gluUnproject gives you the coordinates in the opengl model (3D!). So it’s normal if the values from the screen coordinates differ completely from the 3D-coordinates.

Ok thank you Kilam,

By the way, Is it possibe to have the screen mapped in one metric unit, lets say milimiters ? Someone already made this kind of thing, if yes, can you help me ?

Thank you for the moment

Best regards

Kurt

GetDeviceCaps(hDC, HORZSIZE) and
GetDeviceCaps(hDC, VERTSIZE)

gives you the size of your screen in
mm’s. Don’t know, how it works, I think it will work with the monitor settings. Otherwise it couldn’t be determined.

Thank you Kilam,

I will try to work in this way.

Best regards

Kurt