1. Hey! Guest! The 35th GMC Jam will take place between November 28th, 12:00 UTC - December 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice

GML How to maintain correct aspect ratio at fullscreen (using application_surface)?

Discussion in 'Programming' started by hdarren, Nov 1, 2019.

  1. hdarren

    hdarren Member

    Joined:
    Jun 21, 2016
    Posts:
    278
    Usually in GameMaker if you go fullscreen then it adds a nice black letterbox to maintain correct aspect ratio so that pixels aren't distorted if you ticked that box in the options. But if you turn off the application surface to draw it yourself then it doesn't do this automatically, instead it just stretches it to the complete fullscreen creating ugly pixels.

    I'm drawing the application surface myself so I can do things to it like I got some cool shaders from the market place. :)

    This is the code I'm using in my object that now draws the application surface, it is the Post-Draw event

    Code:
    if global.vFullscreen {var a=application_get_position(); xx=a[0]; yy=a[1]; ww=a[2]-a[0]; hh=a[3]-a[1];}
    else {xx=0; yy=0; ww=global.vResolution_Width; hh=global.vResolution_Height;}
    
    draw_surface_stretched_ext(application_surface,xx,yy,ww,hh,-1,1);
    I'm having a lot of trouble trying to figure out the maths of how to maintain the aspect ratio correctly.

    I couldn't find much from searching but I did find this topic which had some code to do this but it doesn't seem to do anything.
    https://forum.yoyogames.com/index.p...n-resolution-in-game-maker.54482/#post-331430

    Any help appreciated! :)
     
  2. Jakylgamer

    Jakylgamer Member

    Joined:
    Jun 27, 2016
    Posts:
    511
    maybe youre looking for
    Code:
    surface_resize(application_surface,width,height) 
    ?
     
  3. hdarren

    hdarren Member

    Joined:
    Jun 21, 2016
    Posts:
    278
    No. The problem is the resized surface is the full fullscreen size so if your desktop resolution can't be multiplied into my game's resolution of 256x144 it skews the pixels. I want it so in fullscreen the aspect ratio is kept to the 256x144 ratio.
     
  4. rIKmAN

    rIKmAN Member

    Joined:
    Sep 6, 2016
    Posts:
    4,611
    How about resizing it to the next full integer scale above the current resolution and then drawing the surface centred?

    It will cut off a little of the game along the edges but it would retain the 1:1 pixel ratio, whether that would be acceptable depends on your game.
     

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