love2d / love-android

Android build setup for LÖVE.
https://love2d.org
Other
200 stars 70 forks source link

How is screen resolution handled? #233

Closed ravener closed 1 year ago

ravener commented 2 years ago

I'm quite confused about how screen resolutions is handled and I found that in love.load I have a smaller width/height returned by love.graphics.getWidth()/getHeight() but immediately after love.resize is called with the correct values. Is this an expected behavior or a bug? Lots of examples and code around initialize stuff in love.load which if they used love.graphics.getWidth()/getHeight they'd all be working with smaller values than the actual size.

If this is the expected way, can't we somehow make it so atleast the initial love.resize is called before we get to love.load? What's the best way to deal with sizes in this manner?

MikuAuahDark commented 2 years ago

I tried to reproduce your case with this code (with resizable = true and fullscreen = true at love.conf):

local textlog = {}

local function addLog(text)
    table.insert(textlog, 1, text)
    textlog[6] = nil
end

function love.load()
    refreshrate = select(3, love.window.getMode()).refreshrate or 0
    addLog(refreshrate.."Hz "..string.format("%dx%d", love.graphics.getDimensions()))
end

function love.draw()
    love.graphics.print(table.concat(textlog, "\n"), 32, 32)
end

function love.resize(w, h)
    addLog("new resize "..w.."x"..h)
end

function love.keyreleased(k)
    if k == "escape" then love.event.quit() end
end

And I can confirm it indeed fires love.resize event just after love.load. My best guess is this is caused by love2d/love@9c4db00e9490742317d4a493f5c11d7f7e200124, but that commit is there to workaround love2d/love-android#196 so this is confusion on its own.

MikuAuahDark commented 1 year ago

Probably not gonna fixed in 11.x.

ravener commented 1 year ago

Currently the workaround is to manually set fullscreen love.window.setFullscreen(true) inside love.load instead of using fullscreen = true. This works as expected.