natiny.window.set_scale_mode
natiny.window.set_scale_mode(win, mode)
Selects how 2D drawing is enlarged on a display that uses scaling.
Parameters
| Name | Type | Description |
|---|---|---|
win |
number |
Window handle from natiny.window.create |
mode |
number |
One of the constants below |
Modes
| Constant | Behavior | Result |
|---|---|---|
natiny.window.SCALE_MODE_PIXELS |
Draws pixel for pixel | One drawing unit equals one window pixel; display scaling is ignored; default |
natiny.window.SCALE_MODE_STRETCH |
Stretches the finished frame | Draws a smaller frame and enlarges it to fill the window; may look blurry |
natiny.window.SCALE_MODE_HIDPI |
Draws at full detail | Enlarges coordinates while drawing to all window pixels; shapes and text stay sharp |
A drawing unit is the unit used for positions and sizes in 2D drawing commands.
If natiny.window.get_scale returns 2, coordinate 100 reaches
pixel 200 in SCALE_MODE_STRETCH and SCALE_MODE_HIDPI. In
SCALE_MODE_PIXELS, it reaches pixel 100. Window dimensions and mouse input
always use the same units as 2D drawing.
For a practical explanation and help choosing a mode, see Window scaling.
Example
local win = natiny.window.create("My App", 1280, 720)
natiny.window.set_scale_mode(win, natiny.window.SCALE_MODE_HIDPI)
local font = natiny.font.create(ttf, 16)
natiny.backend.loop(function(dt)
natiny.window.bind(win)
local w = natiny.window.get_width(win)
local h = natiny.window.get_height(win)
natiny.render.rectangle(20, 20, 300, 40)
natiny.render.text(font, 30, 30, "hello")
natiny.window.unbind()
end)
Notes
- Call this function outside
natiny.window.bind; calls for a bound window are rejected. - Changing the mode may rebuild live font atlases and allocate or release an offscreen surface. Do not call it every frame.
- The selected mode does not affect 3D drawing or drawing into surfaces. Surface dimensions remain in pixels.
natiny.render.scissor_beginandnatiny.render.viewport_beginuse the selected coordinate system.