How does a 1:1 square fit a 4:3 monitor?

Hi all,

My gaming resolution is 4:3 (1024x768). I have a png file thats the same resolution. I wish to use this image as the background for my game. Problem is that when i try to map this image onto a 4:3 polygon the polygon doesnt fit the screen (the width fits but the height is short).

When i map the image onto a 1:1 polygon (a square :-)) instead of the 4:3 rectangle, the square fits the screen perfectly (i have no idea how because the square is 1024x1024 where the monitor is 1024x768). However it stretches the background image mapped onto it (it stretches it vertically because a 4:3 image is being mapped on to a 1:1 square).

Any ideas whats going on?

Thanks

It sounds like the extents you defined were 1.0 by 1.0, or at least a multiple of 1.0s. In other words, you told OpenGL:

Yes I have a 4:3 aspect ratio, but I don’t want to think about it, so make it 1:1 for me.

A simple way of doing just that is:

glViewport(0,0,1024,768);
//…
glFrustum(0.0,1.0,0.0,1.0,//near and far planes);
// Or with glOrtho

In this instance, OpenGL knows your viewport is 1024x768 (4:3 aspect ratio), but you’re telling OpenGL that you want an aspect ratio of exactly 1:1. So it takes care of the math, leaving you with a puzzling situation.

But without seeing any code, this is all just guessing on my part.

i believe you are right in what is wrong with it. What values do i use in glViewport to change this? Thanks

You don’t change glViewport…you change glFrustum or glOrtho:

glViewport(0,0,width,height);
float aspect=(float)width/(float)height;
glFrustum(-aspect,aspect,-1.0,1.0,/* near and far planes */);
// or glOrtho

Of course, you can change it to 0,aspect,0,1.0 if it’s important to you to have no negative coordinates. :slight_smile:

What you fail to understand is the fact, that opengl does not work with window coordinates directly. The coordinates you send in (via Vertex etc. commands) are transformed by various matrices. This way, the coordinates (0,0) and (1, 1) may actually refer to window coordinates (0, 0) and (1023, 767). Refer to documentation.