# How to convert pixel coordinates to GL coordinates in 2D space?

I know that if you want to display a sprite on screen (in 2D) you can use glOrtho and essentially make 1 gl unit equal to 1 pixel, so when I plot out the vertices for say a 128x128 image (on a quad), I can define the vertices as -64/64, -64-64, etc and then when I map my texture coords to that quad, the image is displayed at a 1:1 ratio.

However, lets say I wanted to not use glOrtho and wanted to have a perspective view, so I can combine 2D sprites with 3D models and whatnot? I'm at a loss on how to convert/set up the coordinates for the planes/quads I want to draw images to, in a way that will match the resolution of the image. That is, define coordinates or convert them in such a way so that when a 2D sprite is right at the near plane, that sprite is mapped as 128x128 pixels on the screen.

• completely off topic: have more self confidence! – Ali1S232 Sep 21 '11 at 23:50
• (not big enough for a full answer, so I leave a comment) You can use two projections and draw your scene in two passes. Just don't erase or flood fill the back buffer between passes. – Patrick Hughes Sep 22 '11 at 1:01
• This is easy enough to do. If it's not well answered when I get home from work, I'll do a big write up for you. – Jordaan Mylonas Sep 22 '11 at 1:16
• Nathans answer actually makes sense to me and it was what I was thinking all along, I just thought perhaps there was a better way. But please by all means do a big write up for me! lol the more information the better! – user6484 Sep 22 '11 at 1:29
• @Ascension, it's a policy on SE sites to make questions more useful. The parts I removed were irrelevant to the core of your question. meta.stackexchange.com/questions/2950/… – Tetrad Sep 22 '11 at 5:32

screen_width_in_world = 2.0 * tan(0.5 * horizontal_fov) * near_clip_distance