Skip to content

sokol_android: setScreenHeight should use design height, not actual framebuffer height #158

Closed

Description

@apotema

Problem

backends/sokol/templates/mobile.txt passes the runtime actual_h from window.height() to g.setScreenHeight() in the frame() callback:

// mobile.txt — broken
const actual_h = window.height();
BackendGfxType.setScreenSize(actual_w, actual_h);
g.setScreenHeight(@floatFromInt(actual_h)); // ← should use design height

On Android with high_dpi = false (sokol default), window.height() returns half the physical pixel height (e.g. 540 on a 1080px screen). The renderer uses this as its logical screen height, so renderer.toScreenY(design_h) computes a negative value and screen-space background sprites appear off-screen.

Fix

The template already declares screen_h: u32 = {{height}} (the project design height). Use it for setScreenHeight while setScreenSize continues to receive the actual framebuffer dimensions:

// mobile.txt — fixed
const actual_w = window.width();
const actual_h = window.height();
BackendGfxType.setScreenSize(actual_w, actual_h); // gfx backend: actual pixels for NDC
g.setScreenHeight(@as(f32, @floatFromInt(screen_h))); // renderer: design height for world→screen Y

File

backends/sokol/templates/mobile.txt, line 30.

Impact

All Android projects using the sokol backend where screen-space (background/UI) sprites are positioned using the design height.

Activity

  1. added a commit that references this issue on Apr 13, 2026
    027616f
  2. apotema commented on Apr 17, 2026

    @apotema
    ContributorAuthor

    Fix landed in labelle-toolkit/labelle-assembler#24 after the sokol backend was ejected from labelle-cli to labelle-assembler (via #150). Verified on current assembler main:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions