Skip to main content
GameDev.net gamedev.net
🔒 Locked

Getting correct Ortho2D view...

Started by microdot Jul 26, 2002 at 3:00 PM 5 replies 11.4k views
Original Post
microdot
microdot
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.
<span class="smallfont">That is not dead which can eternal lieAnd with strange aeons even death may die.   -- "The Nameless City" - H. P. Lovecraft</span>
microdot
microdot
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.
<span class="smallfont">That is not dead which can eternal lieAnd with strange aeons even death may die.   -- "The Nameless City" - H. P. Lovecraft</span>
microdot
microdot
Thanks for the link. It doesn''t appear to be working at the moment, but I''ll check it out as soon as it does.
<span class="smallfont">That is not dead which can eternal lieAnd with strange aeons even death may die.   -- "The Nameless City" - H. P. Lovecraft</span>
Ziphnor
Ziphnor
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!!!"


microdot
microdot
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.
<span class="smallfont">That is not dead which can eternal lieAnd with strange aeons even death may die.   -- "The Nameless City" - H. P. Lovecraft</span>

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.