GML How can I make viewport smaller than window size?

Discussion in 'Programming' started by Xalezar, Oct 5, 2019.

  1. Xalezar

    Xalezar Member

    Joined:
    Jul 27, 2018
    Posts:
    13
    Been trying to make my viewport 0 smaller than the game window, but whatever size I set the viewport to, it becomes stretched to fill the game window, so it ends up being distorted (stretched out vertically). What I've done so far in my mgr_camera persistent object that is instantiated at the start of the game in room rm_init, which has dimensions 160 x 284. Immediately after mgr_camera is instantiated, the player is transported to a new map where he can walk around.

    [​IMG]

    What I've attempted so far:

    Code:
    /* Create */
    
    camera = camera_create();
    
    /* Room Start */
    
    view_enabled = true;
    view_visible[0] = true;
    
    view_xport[0] = 0;
    view_yport[0] = 0;
    
    view_wport[0] = 160;
    view_hport[0] = 160;
    
    view_camera[0] = camera;
    
    var pm = matrix_build_projection_ortho(view_wport[0], view_hport[0], -9999, 9999);
    camera_set_proj_mat(camera, pm);
    
    var vm = matrix_build_lookat(view_wport[0]/2, view_hport[0]/2, -10, view_wport[0]/2, view_hport[0]/2, 0, 0, 1, 0);
    camera_set_view_mat(camera, vm);
    Any help is appreciated, thanks.
     
    Last edited: Oct 6, 2019
  2. Relic

    Relic Member

    Joined:
    Jun 27, 2017
    Posts:
    720
    In addition to this code, have you checked the settings of your game? In the resource tree the Main item has a graphics tab - check whether your game is resizing to fit the window or keeping aspect ratio.

    The camera code itself I can’t debug from memory alone sorry.
     
  3. Lady Glitch

    Lady Glitch Member

    Joined:
    Feb 10, 2019
    Posts:
    25
    Lord KJWilliams and Xalezar like this.
  4. Xalezar

    Xalezar Member

    Joined:
    Jul 27, 2018
    Posts:
    13
    It worked, thanks!

    I used:

    Code:
    surface_resize( application_surface, 160, 160 );
    Later, I might end up using multiple surfaces, so that I can draw on the area that is not the main camera view. I plan to use the rest of the screen for a touch-input area for a mobile experience in portrait mode.
     
    Lady Glitch likes this.
  5. Xalezar

    Xalezar Member

    Joined:
    Jul 27, 2018
    Posts:
    13
    Yeah, the maintain ratio is checked off.
     
  6. Relic

    Relic Member

    Joined:
    Jun 27, 2017
    Posts:
    720
    Check it on then!
     
  7. Xalezar

    Xalezar Member

    Joined:
    Jul 27, 2018
    Posts:
    13
    By checked off, I meant it in the colloquial sense, as in it has a check mark in it lol.
     
    ParodyKnaveBob, Relic and HayManMarc like this.
  8. Relic

    Relic Member

    Joined:
    Jun 27, 2017
    Posts:
    720
    I hear you - just marked 60 test papers asking whether an alarm was on or off. So many “the alarm goes off” phrases. Is that on or off? Lol
     
    ParodyKnaveBob likes this.
  9. samspade

    samspade Member

    Joined:
    Feb 26, 2017
    Posts:
    2,037
    Essentially, you can't. Not that way. See these posts for explanation: https://forum.yoyogames.com/index.p...port-not-changing-anything.65147/#post-389964.

    (if anyone from YoYo is reading this, I still think GM provided functions should work, or if they're going to be overridden that should be put in the manual so I and others don't waste so much time trying to debug intended behavior. Or maybe it is and I missed it.)
     
    Last edited: Oct 7, 2019
  10. Xalezar

    Xalezar Member

    Joined:
    Jul 27, 2018
    Posts:
    13
    I see, thanks for sharing your experiences with this issue. I think a possible easier workaround for me might be just to use the whole screen, but cover up the portion where I want it to be blank. I think performance will be negligible. Context: the area that I want to be left blank, will be used to accept touch gestures so that the player's fingers don't obscure the camera view. Just trying out this user interface to see how it feels.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice