Mouse x,y to world x,y

How can I convert the current mouse x,y from pixels to world space in Ortho view ?

My calculations are messed, obv it works if it is a 1 to 1 ratio, that is

cursor.x = x
cursor.y = SCREEN_HEIGHT - y

however this is not realistic as my screen height and perpective height etc… may never be the same.

I was trying to get a ratio of the different sizes

cursor.x = x / (SCR_PIXELSX/ORTHO_WIDTH)

this does not work either, I want to just move a quad with the same cursor pos for my gui.

any ideas ?

look up gluProject and gluUnproject. you will need to get the viewport and the projection/modelview matrices to use these funcitons.