summaryrefslogtreecommitdiff
path: root/main.lua
diff options
context:
space:
mode:
authorcursed22bc <admin@pixeldawn.org>2026-02-27 13:37:36 +0200
committercursed22bc <admin@pixeldawn.org>2026-02-27 13:37:36 +0200
commitf8da1a788c68ff58d53a173ad197ef3623dc6cff (patch)
tree63d417cac1782968a556675acbc8a506504d9069 /main.lua
parentc528c8fa70a1399efc746be6468bd7d36abe1ca2 (diff)
base setup
Diffstat (limited to 'main.lua')
-rw-r--r--main.lua90
1 files changed, 90 insertions, 0 deletions
diff --git a/main.lua b/main.lua
new file mode 100644
index 0000000..66ef333
--- /dev/null
+++ b/main.lua
@@ -0,0 +1,90 @@
+local VIRTUAL_WIDTH, VIRTUAL_HEIGHT = 16*10*3, 9*10*3
+local CANVAS_PADDING = 6
+local CANVAS_WIDTH = VIRTUAL_WIDTH + CANVAS_PADDING
+local CANVAS_HEIGHT = VIRTUAL_HEIGHT + CANVAS_PADDING
+local WORLD_TO_CANVAS = 3
+
+local scale = 1
+local finalScale = 1
+local offsetX, offsetY = 0, 0
+local dpiScale = 1
+local canvas = nil
+local smoothCameraShader = nil
+
+--TODO: separate to components
+local cameraModule = require("camera")
+local camera = nil
+-- end
+
+local fonts = require("fonts")
+
+
+local function recalcScale(w, h)
+ dpiScale = (love.window.getDPIScale and love.window.getDPIScale()) or 1
+ scale = math.max(1, math.floor(math.min(w / VIRTUAL_WIDTH, h / VIRTUAL_HEIGHT) / dpiScale))
+ finalScale = scale * dpiScale
+ offsetX = math.floor((w - VIRTUAL_WIDTH * finalScale) / 2)
+ offsetY = math.floor((h - VIRTUAL_HEIGHT * finalScale) / 2)
+end
+
+function love.load()
+ camera = cameraModule:new({x = 0, y = 0, width = VIRTUAL_WIDTH, height = VIRTUAL_HEIGHT}, VIRTUAL_WIDTH, VIRTUAL_HEIGHT, true, WORLD_TO_CANVAS)
+ love.graphics.setDefaultFilter("nearest", "nearest")
+ love.window.setTitle("Openformer")
+ fonts.load()
+ love.graphics.setFont(fonts.default)
+
+ canvas = love.graphics.newCanvas(CANVAS_WIDTH, CANVAS_HEIGHT)
+ canvas:setFilter("nearest", "nearest")
+
+ local ok, shader = pcall(love.graphics.newShader, "shaders/smooth_camera.glsl")
+ smoothCameraShader = ok and shader or nil
+ if not smoothCameraShader then
+ print("Warning: smooth_camera.glsl not loaded, using fallback (no sub-pixel offset)")
+ end
+
+ local w, h = love.graphics.getWidth(), love.graphics.getHeight()
+ recalcScale(w, h)
+
+end
+
+function love.resize(w, h)
+ recalcScale(w, h)
+ if canvas then canvas:release() end
+ canvas = love.graphics.newCanvas(CANVAS_WIDTH, CANVAS_HEIGHT)
+ canvas:setFilter("nearest", "nearest")
+end
+
+
+function love.update(dt)
+ if not camera then return end
+ camera:update(dt)
+end
+
+function love.keypressed(key, scancode, isrepeat)
+ if key == "f11" then
+ love.window.setFullscreen(not love.window.getFullscreen(), "desktop")
+ end
+end
+
+function love.draw()
+ love.graphics.setCanvas(canvas)
+ love.graphics.clear()
+ love.graphics.push()
+ if camera then
+ camera:set()
+ love.graphics.print("FPS: " .. love.timer.getFPS(), 10, 10)
+ love.graphics.pop()
+
+ camera:unset()
+ end
+
+ love.graphics.setCanvas()
+
+ love.graphics.clear()
+ local drawX = offsetX - (CANVAS_PADDING * finalScale) / 2
+ local drawY = offsetY - (CANVAS_PADDING * finalScale) / 2
+ love.graphics.draw(canvas, math.floor(drawX), math.floor(drawY), 0, finalScale, finalScale)
+end
+
+return nil \ No newline at end of file