So I've been trying to get resolution setting to work correctly in my game for a while to no avail. I have a 16:9 ratio which I am trying to keep constant. I am using SDL with openGL. And here's my changing resolution class:
#ifndef _RESOLUTION_CPP_
#define _RESOLUTION_CPP_
#include "Main.h"
class Resolution{
public:
static void ChangeResolution(SDL_Surface* Screen,int Width,int Height, bool FullScreen){
int Full = 0;
if(FullScreen){
Full = SDL_FULLSCREEN;
}
Screen = SDL_SetVideoMode(Width , Height, 32, SDL_HWSURFACE | SDL_GL_DOUBLEBUFFER | SDL_OPENGL| Full);
glClearColor(0, 0, 0, 0);
glClearDepth(1.0f);
glViewport(0, 0, Width, Height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//glOrtho(0, Width, Height, 0, 1, -1);
glOrtho(0, 960,540, 0, 1, -1);
glMatrixMode(GL_MODELVIEW);
glEnable(GL_TEXTURE_2D);
glLoadIdentity();
}
};
#endif
Now at first I had glOrtho set to scale along with the window size and view port, but that made me see more of the screen as the window size got larger, which wasn't what I wanted. So by setting the camera (glOrtho is like the camera right?) To a constant width and height I was able to always see the same portion of the screen. So far so good.
Now trying the game in window mode, everything works exactly as it should. The game's graphics scale, keeping the aspect ratio, and I always see the same portion of the screen.
Now trying full screen on a 5:4 monitor, this is what I get:
Left: 960x540--- Middle:1024x576--- Right:1200x675
As you can see, only the one in the middle is working as it should, it's stretched to fill the screen, but not stretched to destroy the aspect ratio. The one on the left is keeping it's aspect ratio, but not scaling enough.
The one on the right is getting stretched vertically and the aspect ratio is broken. Why is that? Why would it get stretched like that?
Also, how would I go about centering the screen so that, on the middle monitor, the would be a black space on top and bottom, not just one big one at top?
Additional info:
When I try this on a 16:10 laptop, I get similar results with the screen not being scaled enough or not being centered, but it never stretched. Even setting it at a huge resolution of 1920,1080. It exactly scales more than the screen such that I only see a small part, but I'm guessing you can't really squeeze a 1920x1080 on a much smaller resolution.
So my question is really: Why is the resolution thing being completely unpredictable? Sometimes it stretches, sometimes it doesn't scale enough, etc.. and how do I fix that?