Getting correct Ortho2D view...

Started by
5 comments, last by microdot 21 years, 8 months ago
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>
Advertisement
How about the square drawing code? Is it like glVertex2f(0.5f,0.5f), etc?
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>
NOO! Not another post about 2d!

Please visit The gl2D Project for all your 2D needs.


For your problem, just click on the articles link at the top of my page and the only article in there gives you a very easy way to correctly setup OpenGL in 2D.

~ Jesse

OpenGL_2D Project
----------[Development Journal]
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>
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!!!"


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>

This topic is closed to new replies.

Advertisement