GameMaker [SOLVED] Scale viewport to resizable window

S

Swyrl

Guest
Hey, so I've been grappling with something for a while now, and I can't quite seem to get it to function correctly-

My game has a resizable window, and essentially what I'm trying to do is detect when the window is resized (which I've done) and then resize the viewport to fill the window. I've tried several different techniques, but for the life of me I just can't get the viewport to change size. (the most recent thing I tried was calling it along with window_set_size(), but that didn't seem to do anything.)

One thing I tried before was resizing the application_surface, which sort of worked, but later on led to major issues with more complex cameras, and while I may be able to get it working with a lot of work, I'd rather not resort to something so hacky.

My current resizing code looks something like this-
Code:
win_wid=window_get_width();

win_hgt=window_get_height();
view_wport[0]=win_wid;
view_hport[0]=win_hgt;
aspect=room_width/room_height;
if aspect <= win_wid/win_hgt {
    scale=win_wid/room_width;
    //view_yport[0]=(win_hgt-(room_height*scale))/2;
    camera_set_view_pos(simplecam,0,(win_hgt-(room_height*scale))/2);
} else {
    scale=win_hgt/room_height;
    //view_xport[0]=(win_wid-(room_width*scale))/2;
    camera_set_view_pos(simplecam,(win_wid-(room_width*scale))/2,0);
}
camera_set_view_size(simplecam,room_width*scale,room_height*scale);
and here's one of my other attempts-
Code:
win_height=window_get_height();
win_width=window_get_width();
//camera_set_view_size(maincam,min(win_width,1920),win_height/win_width*min(win_width,1920));
//camera_set_view_size(maincam,min(win_width,1200),win_height/win_width*min(win_width,1200));
if win_height>0 and win_width>0{
scl=max(win_width,win_height)/640*zoom;
scl=min(scl,1.2);
if menu {
    scl=max(win_width/room_width,win_height/room_height);
    global.fscl=min(win_width/room_width,win_height/room_height);
    if win_width/scl >= win_height/scl{
       
    }
    global.menu_xoff=((win_width-(global.fscl*room_width))/2);
    global.menu_yoff=((win_height-(global.fscl*room_height))/2);
   
    show_debug_message(global.fscl);
    show_debug_message(scl);
}

v_wid=win_width/scl;
v_hgt=win_height/scl;
camera_set_view_size(maincam,v_wid,v_hgt);
surface_resize(application_surface,v_wid,v_hgt);
global.rsz=true;
}

Any tips? Is there something stupid I'm doing wrong?
 
S

Swyrl

Guest
I appreciate the gesture, but it's not quite what I'm looking for. I'd like to avoid altering the application_surface if at all possible, and I'd like to be able to support an arbitrary window aspect, especially given older monitors that don't use 16:9 and newer, widescreen monitors. I already have code for handling zoom levels, but altering the application surface's aspect ratio seems to distort screen space somehow. (I believe it's related to that bug you mentioned with mouse coordinate detection.)

EDIT: After a great deal of digging, I've found a solution-
the trick is to set the application to "full scale" mode, then resize the view accordingly. Here is my scaling code, in case anyone else wants to use it.
Code:
win_wid=window_get_width();
win_hgt=window_get_height();
if win_wid/win_hgt>=aspect {
    //wider
    scale=win_wid/o_wid;
} else {
    //taller
    scale=win_hgt/o_hgt;
}
view_hport[0]=win_hgt;
view_wport[0]=win_wid;
camera_set_view_size(maincam,win_wid/scale,win_hgt/scale);
It's a bit simplistic but it does the job.
(NOTE: o_wid & o_hgt are the default/basis dimensions of your viewscreen. they define the default window size and the aspect ratio the view scales upon.)
 
Last edited by a moderator:
B

bigtunacan

Guest
I appreciate the gesture, but it's not quite what I'm looking for. I'd like to avoid altering the application_surface if at all possible, and I'd like to be able to support an arbitrary window aspect, especially given older monitors that don't use 16:9 and newer, widescreen monitors. I already have code for handling zoom levels, but altering the application surface's aspect ratio seems to distort screen space somehow. (I believe it's related to that bug you mentioned with mouse coordinate detection.)

EDIT: After a great deal of digging, I've found a solution-
the trick is to set the application to "full scale" mode, then resize the view accordingly. Here is my scaling code, in case anyone else wants to use it.
Code:
win_wid=window_get_width();
win_hgt=window_get_height();
if win_wid/win_hgt>=aspect {
    //wider
    scale=win_wid/o_wid;
} else {
    //taller
    scale=win_hgt/o_hgt;
}
view_hport[0]=win_hgt;
view_wport[0]=win_wid;
camera_set_view_size(maincam,win_wid/scale,win_hgt/scale);
It's a bit simplistic but it does the job.
(NOTE: o_wid & o_hgt are the default/basis dimensions of your viewscreen. they define the default window size and the aspect ratio the view scales upon.)
I see this thread is a bit old, but I'm trying to do the same thing and it looks like the solution is not displaying some of the code that was used.

I was just wondering how were these calculated?

  • o_wid
  • o_hgt
  • maincam
 
Top