Archived

This topic is now archived and is closed to further replies.

Getting correct Ortho2D view...

This topic is 5621 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I was playing around with the glOrtho2D projection, and after fiddling with with my numbers, I got it to display correctly. Well, not quite. I was trying to render a _square_ quad smack in the middle of the view. The quad was centered; the problem is the quad came out rectangular. Now, my glOrtho2D projection at this point was ( -1.0f, 1.0f, -1.0f, 1.0f), so I figured the problem was I needed to adjust the glOrtho2D projection to account for the aspect ratio of the glViewport. So I started putting in different values making the glOrtho2D projection wider. I didn''t notice any differance in the output. Anything significantly noticable anyway. So... Does anybody know perhaps what I''m doing wrong. I''ve totally discounted it having anything to do with the glViewport itself. Thanks for any suggestions.

Share this post


Link to post
Share on other sites
Thanks, but it''s not so much that I want the square it''s that I want a proper projection where a square quad is in fact square. In the end I want to be able to draw whatever I want and have it rendered correctly in the orthogonal projection. Thanks anyway.

Share this post


Link to post
Share on other sites
You need the right aspect ratio for square things to be square
For example i set my projection similar to you( glOrtho(-1.0f,1.0f,-1.0f,1.0f,-10,100), but when setting the modelview i scale like this:
glScalef(2.0f/width,-2.0f/height,1);
[the - in front of the the height part is to reverse the y-axis, after that i just translate to the upper left corner so the graphics coordinate system has 0,0 in top left and y increases going downwards}.

There is probably a better way to do it though

Btw, why are people so pissed about 2D questions? The next time someone asks a 3D question, ill be sure to respond, " oh no, yet another 3d question!!!"


Share this post


Link to post
Share on other sites
Yay. Problem fixed. I was setting up my glOrtho2D projection too early. I needed to do it after I had made the render context. And I factored in the aspect ratio in the projection so I got ( -1.0, 1.0, -0.75, 0.75 ). Now the quad is square. Thanks for all the suggestions.

Share this post


Link to post
Share on other sites