opengl view, projections and orthographic aspect ratio
<p>There's a lot of great tutorials out there on opengl projection matrices for 3D but I am not doing 3D. I am really having a tough time getting orthographic projection setup to my liking.</p>

<p>int width = 320;
int height = 480;</p>

<p>I create a view projection matrix with these settings.</p>

<pre><code>//eyex, eyey, eyez, centerx, centery, centerz, upx, upy, upz//
matrix view = (0, 0, -20, 0, 0, -1, 0, 1, 0);

matrix projection = (0, width, 0, height, 1, 100);
glViewport(0, width, 0, -height);
</code></pre>

<p>After creating this view and projection matrix and passing them to the gpu.</p>

<p>Then I create a quad going from <code>-1,-1 to 1, 1</code> so that it's origin is at the center.</p>

<p>then I make a scale matrix for the quad so that I can actually see it on the screen. It's rendering as a perfect square but of course the glViewport or the perspective matrix shouldn't be square. It should be rectangle.</p>

<p>How can I setup the glViewport as well as the perspective matrix so that I can maintain aspect ratio.</p>

<p>for example I now have the aspect ratio which is width/height. How do I use that with the projection matrix and the glviewport?</p>

<p>@Reto is probably correct that I am overthinking this but opengl application interface is a bit tricky for me.</p>

<p><strong>edit</strong>
I drew an image in hopes to help clarify things.</p>

<p>Let's say that I want my viewport to be 320x480 pixels. I'd like two different scaling modes that I can choose from. Either keep a fixed height
where the width will grow to show more horizontal view or a fixed width with a growing height to show more vertically.</p>

<p>here's the image<a href="https://i.stack.imgur.com/goR4a.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/goR4a.png" alt="enter image description here"></a></p>

<p>Let's say I design a scene around 320x480 and I lay everything out and I know that I would like to scale the width larger but keep a fixed height.</p>

<p>How can I achieve that with the glViewport and orthographic projection matrix from my aspect ratio?</p>