Legacy GM SOLVED view_wview and hview are wrong on different resolutions

E

EulogyForTheFallen

Guest
Hello good people of the forum, I have an interesting problem that I've been trying to fix for a while now and I think I'm going to lose my mind. Basically, the problem is with scaling. I've read every tutorial and article on the subject, and none of them helped me. The problem is this: My target resolution is 1080p, and as such all of the rooms' view_wview and view_hview settings are set to 1920x1080. I have a master object that is placed in the first room (screenSplash) with the room editor, and in this object's Game Start event I run this script:
Code:
var ww = window_get_width();
    var hh = window_get_height();
    var xx = window_get_x();
    var yy = window_get_y();
    var ar = hh/ww;
    display_reset(0,false);
    display_set_windows_alternate_sync(true);
    if(ww > 2048){  //If the player has a very high resolution, play at 1 to 3.
        view_wview[0] = ww/3;
        view_hview[0] = hh/3;
    }else if(ww > 960){ //If the player has a decently high resolution, play at 1 to 2.
        view_wview[0] = ww/2;
        view_hview[0] = hh/2;
    }else{  //If the player has a low resolution, play at 1 to 1.
        view_wview[0] = ww;
        view_hview[0] = hh;
    }
    view_wport[0] = ww;
    view_hport[0] = hh;
    display_set_gui_size(1920, 1920*ar);
    surface_resize(application_surface, ww, hh);
   
    if(room == screenSplash){
        room_width = view_wview[0];
        room_height = view_hview[0];
        var i = true;
        var rm = room_next(room);
        while (i){
            room_set_view(rm, 0, true, 0, 0, view_wview[0], view_hview[0], 0, 0, view_wport[0], view_hport[0], view_wview[0]/2, view_hview[0]/2, -1, -1, obj_act);
            room_set_view_enabled(rm,true);
            if(rm == room_last){
                i = false;
            }else{
                rm = room_next(rm);
            }
        }
        show_debug_message("All rooms' views set.");
    }
    show_debug_message("Width: " + string(ww));
    show_debug_message("Height: " + string(hh));
This works just fine on my laptop's 1080p screen. The problem is that when I try it on my 1280x1024 monitor and use debug messages to print the values of view_wview and view_hview, they tell me the correct values: 640x512. But when I actually play the game, it looks like this:



The red rectangle is a debug draw that represents the view. If my script was working correctly, it should be drawn around the edges of the screen. Here is the code I use to draw it and the grid:
Code:
//Draw rectangle to test screen dimensions.
draw_set_color(c_red);
draw_rectangle(view_xview[0],view_yview[0],view_xview[0]+view_wview[0],view_yview[0]+view_hview[0],true);
///DRAW 32x32 GRID
draw_set_color(c_black);
for(var xPos = -1; xPos < room_width; xPos += 32)
    draw_line_color(xPos,0,xPos,room_height,c_black,c_black);
for(var yPos = -1; yPos < room_height; yPos += 32)
    draw_line_color(0,yPos,room_width,yPos,c_black,c_black);
So clearly my script changes the values of view_wview and hview, along with wport and hport because debug statements confirm it and the red rectangle is drawn correctly. But somehow, even though the values were changed, the game still uses the 1080p values for the actual view. Does anyone have any idea why this is happening? I'm using GM:S v1.4.1757 on Windows 10. Thanks :D
 

jo-thijs

Member
Hi and welcome to the GMC!

I suppose the room start code has not yet been executed when in the screenSplash room,
as this code is invalid and should throw an error:
Code:
        room_width = view_wview[0];
        room_height = view_hview[0];
Now, I don't directly see what's causing the issue you're having.
Could you provide us with more information?

For instance, can you output the value of view_current, view_enabled, window_get_width() and window_get_height() through show_debug_message
in the code you're using to draw the red rectangle and the black grid?

Is there any other relevant code?

Could you perhaps even temporarilly upload the gmz file of your project somewhere and share the link?
 
E

EulogyForTheFallen

Guest
Hello and thanks for the fast reply. First, I know the code is being run because the debug statements in the script are printing. But the debug statements you asked me to print are kinda interesting.
View current: 0
View enabled: 1
Window width: 1280
Window height: 1024
View current: 1
View enabled: 1
Window width: 1280
Window height: 1024
View current: 2
View enabled: 1
Window width: 1280
Window height: 1024
For some reason, the current view keeps going from 0 to 7 and then back to 0 again.
There shouldn't be any other relevant code and I'll see if I can give you a link to the project, although it is kinda big.

EDIT: Actually, doesn't the current view make sense? Because it's in the draw event so it should get called for each view. So it's actually nothing.
EDIT 2: Actually, the other views aren't visible so why are their draw events getting called?
 
Last edited by a moderator:

jo-thijs

Member
That means multiple views are being drawn.
Try find something that makes views 1 to 7 visible
and correct it by making them invisible.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Where do you call window_set_size? It needs to be called and set to the same size as the view port... although I'm not sure that will resolve the issue, it is something that you seem to be missing. Also, don't forget to clean the compiler cache (green broom at the top) as a corrupted cache can sometimes give very weird errors... and if you are seeing multiple views being called in the debug output then you have something very wrong with the setup. Make sure you haven't accidentally enabled all the views in the room editor?
 
E

EulogyForTheFallen

Guest
Thanks jo, that resolved the issue. The problem was that I am using Tiled Map editor to make my tiled maps and I wrote my own parser to convert the tmx file to .room files. I didn't know about this, and apparently just wrote all of the views as visible. Thanks a lot!
 
Top