Need help with upscaling to fullscreen resolution
Posted: Wed Nov 08, 2017 11:55 pm
Hi! I'm making a little demo on LÖVE to learn the basics and I can't figure out how to make the game upscale when going into fullscreen. I'm aware that there's already many topics regarding the subject, but I need instructions step-by-step as I'm new to programming and math is definitely not my strongest point.
The native resolution of my demo is 480x270 -- which should be easy to scale to 1080p or even 4k -- so I set t.window.width and t.window.height in conf.lua accordingly. Everything seems normal when running on a window (see attachment demo-windowed), but in fullscreen (see demo-1366x768), contrary to what I'd expect, no stretching/scaling is done and the demo is simply displayed at the upper-left corner.
What I want to do are the following:
Things to consider:
P.S.: Here's my main.lua just in case:
The native resolution of my demo is 480x270 -- which should be easy to scale to 1080p or even 4k -- so I set t.window.width and t.window.height in conf.lua accordingly. Everything seems normal when running on a window (see attachment demo-windowed), but in fullscreen (see demo-1366x768), contrary to what I'd expect, no stretching/scaling is done and the demo is simply displayed at the upper-left corner.
What I want to do are the following:
- Upscale (always with nearest neighbor both x and y) the native resolution (and of course all game assets/coordinates¹/etc) by 4x if the fullscreen resolution (based on desktop res) is 1920x1080, or 8x if it's 3840x2160.
- If fullscreen resolution is 1024x768 or 1366x768, keep it that way, upscale native res by 2x and center the image -- so it maintains both 1:1 scaling and aspect ratio. See demo-center.
- Undo everything when going back to windowed mode -- as I presume LÖVE won't do this automatically.
Things to consider:
- Windowed mode is always 480x270 not resizable.
- I don't need to support resolutions below 1024x768.
P.S.: Here's my main.lua just in case:
Code: Select all
player = { x = 15, y = 140, speed = 150, img = nil }
function love.load()
bg = love.graphics.newImage("assets/bg.png")
player.img = love.graphics.newImage('assets/player.png')
end
function love.update(dt)
if love.keyboard.isDown('escape') then
love.event.push('quit')
end
if love.keyboard.isDown('left','a') then
if player.x > 0 then
player.x = player.x - (player.speed*dt)
end
elseif love.keyboard.isDown('right','d') then
if player.x < (love.graphics.getWidth() - player.img:getWidth()) then
player.x = player.x + (player.speed*dt)
end
end
if love.keyboard.isDown('up','w') then
if player.y > 0 then
player.y = player.y - (player.speed*dt)
end
elseif love.keyboard.isDown('down','s') then
if player.y < (love.graphics.getHeight() - player.img:getHeight()) then
player.y = player.y + (player.speed*dt)
end
end
end
function love.keypressed(key, isrepeat)
if key == "f" then
love.window.setFullscreen(not love.window.getFullscreen(), "desktop")
end
end
function love.draw()
love.graphics.draw(bg)
love.graphics.draw(player.img, player.x, player.y)
end