natiny_window_set_scale_mode

C
void natiny_window_set_scale_mode(NatinyWindow id, int mode);

Selects how 2D drawing is enlarged on a display that uses scaling.

Parameters

Name Type Description
id NatinyWindow Window handle from natiny_window_create
mode int One of the constants below

Modes

Constant Behavior Result
NATINY_SCALE_MODE_PIXELS Draws pixel for pixel One drawing unit equals one window pixel; display scaling is ignored; default
NATINY_SCALE_MODE_STRETCH Stretches the finished frame Draws a smaller frame and enlarges it to fill the window; may look blurry
NATINY_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 NATINY_SCALE_MODE_STRETCH and NATINY_SCALE_MODE_HIDPI. In NATINY_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

C
NatinyWindow win = natiny_window_create("My App", 1280, 720);

natiny_window_set_scale_mode(win, NATINY_SCALE_MODE_HIDPI);

NatinyFont font = natiny_font_create(ttf, 16.0f);

/* inside the frame callback */
natiny_window_bind(win);

int w = natiny_window_get_width(win);
int h = natiny_window_get_height(win);

natiny_render_rectangle(20, 20, 300, 40);
natiny_render_text(font, 30, 30, "hello");

natiny_window_unbind();

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_begin and natiny_render_viewport_begin use the selected coordinate system.
  • NATINY_CONSTANT_TARGET_SIZE stays in pixels. A fragment shader runs per physical pixel.