Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Resolution settings, screen behaving unexplainably


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 OmarShehata   Members   -  Reputation: 205

Like
0Likes
Like

Posted 23 March 2012 - 01:09 PM

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:

Posted Image

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?

Sponsor:

#2 FXACE   Members   -  Reputation: 182

Like
1Likes
Like

Posted 24 March 2012 - 08:51 AM

For each screen size you need to set up a custom glViewport parameters which can be done manually or by formula...
usage:
'Width' - a full-screen window width.
'Height' - a full-screen window heght.
example#1:
I want to do make my screen quadratic (adopting to window width and height) which aligned to center:
glViewport((Width-Height)/2,0,Height,Height); // I took 'Height' as minimal value, so I would have it work on displays which it's width is larget than height
result will look like this:
+-------+--------------+-------+ < my display
|*******|...............|*******|
|*******|.......my...|*******|
|*******|..viewport..|*******|
|*******|...............|*******|
+-------+--------------+-------+
'*' - black pixel.
example#2:
I want to make my screen like film look (let say: 800x320) to get a result like watching a video (with these dimensions) in media player full-screen mode:
float aspectToY = 320.0f/800.0f;
int w = Width;
int h = int(float(w)*aspectToY); //!!! correct me if this is wrong.
glViewport(0, (Height - h) / 2, w, h); // NOTE: this would work if 'height'(ex:320) <= 'width'(ex:800).
the result should be like this (for example if my display would be 800x600):
+---------------------------+ << my display
|************************|
+---------------------------+
|.............my...........|
|.........viewport........|
+---------------------------+
|************************|
+---------------------------+

extra information: OpenGL viewport coordinate system (for glViewport setup):
glViewport(x,y,width,height)
---------window top-------
^-height
|
|....+........+
|................\dimensions(width,height)
|....+........+
|......\offset (x,y)
------------------------> -width
---window bottom-----

As you see (in your screen-shots) screen always aligned on left-bottom corner.
Another thing can be happen:
when your display (monitor) first time using these WxH settings sometimes it could do some shift&amp;scale operation which produces strange screen results...
If this was happend, on LCD\LED monitors do: Menu->Settings->Reset:true

Best wishes, FXACE.

#3 OmarShehata   Members   -  Reputation: 205

Like
0Likes
Like

Posted 24 March 2012 - 10:33 PM

Thank you for the very detailed post and explanation FXACE! I really really appreciate it!

So I've successful managed to get it to work like a movie, and it works perfectly in the window. However, back in full screen, I still game very similar results.

We know the viewport is working now, could it be something else? If it helps, when I try to move my mouse into the black bars in the full screen window, sometimes the mouse can't go there, other times it can.

I'm also curious about this part:

Another thing can be happen:
when your display (monitor) first time using these WxH settings sometimes it could do some shift&amp;scale operation which produces strange screen results...
If this was happend, on LCD\LED monitors do: Menu->Settings->Reset:true


I'm on a laptop, I'm not sure if I have these settings.

Again, thank you very much for all the help so far (and in the other thread too!)

#4 FXACE   Members   -  Reputation: 182

Like
1Likes
Like

Posted 26 March 2012 - 08:48 AM

I'm also curious about this part:

Another thing can be happen:
when your display (monitor) first time using these WxH settings sometimes it could do some shift&amp;scale operation which produces strange screen results...
If this was happend, on LCD\LED monitors do: Menu->Settings->Reset:true

I'm on a laptop, I'm not sure if I have these settings.


From my own experience:
When I'm launching game application which enters to full-screen mode (640x480) on my monitors (LG FLATRONs 1920x1080 & 1680x1050) some part of game's screen becomes outside display or not fully stretched to entire display (some parts of screen are not used). If I would set Menu->Settings->Reset:true (on 640x480 mode) it would automatically, correctly changed (as I expect) and saves in monitor's memory (to load next time shift/scale settings when switching to 640x480 again, this settings are customized and located in each resolution mode).

Labtops have some settings for display (accessed with 'fn' key) but I'm not sure do they have these settings.

If you tested some full-screen applications (with modes:960x540, 1024x576, 1200x675) and they were correctly showed, so this is not a display issue.


I have no experience work with SDL(sorry) but I'm curious about this lines (from your code):

static void ChangeResolution(SDL_Surface* Screen,int Width,int Height, bool FullScreen)
..........
Screen = SDL_SetVideoMode(...)
Is your 'Screen' an output variable too? If yes, you need to change from:
SDL_Surface* Screen // when calling a function with this argument instruct a pointer (which holds an address) would be dublicated
to:
SDL_Surface* &Screen // with this your variable is now linked to input pointer

Best wishes, FXACE.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS