viewport smaller than window without scaling?

I got some trouble with the viewport and window size:
If the viewport is smaller than the window, GM:S scales the view to fit the window anyways. However I do not want that since I want a pixelperfect scale. So I thought I'd manually set the viewport:

// set camera and view size:
view = 0;
win_w = 1600;
win_h = 900;
view_w = 1200; // view is smaller than window
view_h = 675;
window_set_size(win_w, win_h);
camera_set_view_size(view_camera[view], view_w, view_h);

// set the viewpost size to view instead of window:
view_set_wport(view, view_w); 
view_set_hport(view, view_h);

// center the viewport:
view_set_xport(view, 0.5 * (win_w - view_w));
view_set_yport(view, 0.5 * (win_h - view_h));

// resize application surface to view size until it's done:
surface_resize(application_surface, view_w, view_h);
alarm[0] = 1; // if appsrf size is not view size, resize appsrf and set alarm again
What I expected was this:

What I got however is this:

I tried to work around by disabling the automatic drawing of the application surface and then draw it manually but of course then the mouse was off.

What am I missing here?


Kazan Games
Maybe subtract the width and height by the x and y? Maybe the size of the camera (this area inside)? Like:
width - x position
height - y position

Last edited:
Maybe subtract the width and height by the x and y? Maybe the size of the camera (this area inside)? Like:
width - x position
height - y position
I would really like the view port to be the same width as the view though. I tried anyways and noticed something. The result with these lines:
view_set_wport(view, 1200); 
view_set_hport(view, 675);
is exactly the same as with these:
view_set_wport(view, 1); 
view_set_hport(view, 1);
I think GM:S is just scaling the application surface to the whole window instead of to the view-port. I just don't understand how I can prevent that.


Friendly Tyrant
Forum Staff
What you are attempting is pretty much impossible with just a single viewport due to how GMS calculates window size and it being dependent on the viewport size. However, that's not to say it can't be done, as it can! The easiest way to do it is to disable the drawing the application surface by default and then draw it yourself in the draw GUI event. In this way you can set the GUI size independently of the view/camera/app surface size, and then draw the app surface at any position required within that GUI layer. I also think you could do this using two viewports, where view[0] is larger than view[1], and so you would have view[1] centered within view[0]. This would need some controller object to draw the black background ONLY when view[0] is active, and draw everything as normal only when view[1] is active (this can be checked with the view_current variable). That said, I think just using the Draw GUI event would be the ideal solution...
Thanks @Nocturne - I feared as much.

Option A) 2 Views:
I tried the 2 view thing where a second view is as large as the window:
but the drawbacks are too big I think:
  • I'd need to tell every object to only draw in view 1 and
  • I'd need the mouse to not react on button presses when on view 0 but not view 1
Option B) draw the application surface on a gui layer
Controlling the application surface and drawing it to the guy layer seems better but
  • I'd still need the mouse to not react on button pressed when outside the application surface and
  • I'd need to correct mouse_x and mouse_y since those are taken from the viewport.
Option C) give up
What I wanted was offering a pixelperfect scale with the intended aspect in fullscreen. Option C would be not just not offer that.

Guess I need to evaluate whether A, B or C is the best option.

thanks again :)


This could be using one camera 2 views in your room editor settings
ill dropbox you an example
i added the second viewport to demonstrate this, just uncheck it
don't use Gui, the scaling gets messy
I know it not exactly what you want but it van be easily changed to draw the gui objects on the inner view
or limit the actions to just a view

are you only wanting the game action on view 1?,
what is the actual purpose of each view? can you post a screenshot
and i can whip up an example
view0 and view1 are 2 very different creatures, the view0 is the default and determines the window size
is view0 like a big map and view1 the postion within the map?
view1 can be manipulated much easier :)

Love your videos by the way
Last edited:


Friendly Tyrant
Forum Staff
You DO have a third option... Make the camera and viewport adapt to the size of the window, without changing the scale (so the bigger the window the more the player would see.... BUT (since you don't want the player to see more) you could then artificially crop the view to the visible area you want by adding in the black bars yourself over the top using the Draw End or Draw Gui events. You'd still need to check the mouse is within the "visible" area, but that would be a LOT easier since it'll still be in room coordinates and not require any additional scaling. It's a bit of a "hack", but it's 100% doable and would be indistinguishable to the end user from "doing it properly". :)
artificially crop the view to the visible area you want by adding in the black bars yourself
I might try something similar:
  • The application surface fits the window/display like in your idea
  • but instead of drawing black bars over it, I'll draw the application surface part I want to show in post draw.
  • I'll create a function checking whether the mouse is in the visible area and every object checking for collision with the mouse needs to check that function as well.
view0 and view1 are 2 very different creatures
I actually only need one view. The problem is the view port. When using one view only - no matter how large I set its port - the application surface always scales to fit the window (keeping the aspect of course). The idea of using a second view was only to stop the first views port to scale to fit the window. However I think handling two views when I only need one comes with multiple problems I don't really want to deal with. All I wanted to do is a resolution manager and camera that can handle different aspects and offer different options like integer or free scale, keep intended aspect and so on.

Love your videos by the way
Thanks alot :)