Getting correct Ortho2D view...
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.
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.
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
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
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.
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!!!"
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!!!"
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement