Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save peterhellberg/2ff78303715d411ae31260a92fe7c1c5 to your computer and use it in GitHub Desktop.

Select an option

Save peterhellberg/2ff78303715d411ae31260a92fe7c1c5 to your computer and use it in GitHub Desktop.
Virtual screen size in Raylib-Zig
const rl = @import("raylib");
const base = .{
.scale = 10,
.width = 160,
.height = 90,
};
const screen = .{
.width = base.width * base.scale,
.height = base.height * base.scale,
};
pub fn main() anyerror!void {
rl.setConfigFlags(.{
.vsync_hint = true,
});
rl.initWindow(screen.width, screen.height, "Virtual screen size in Raylib");
defer rl.closeWindow();
const display = try rl.loadRenderTexture(base.width, base.height);
defer rl.unloadRenderTexture(display);
const source = rl.Rectangle{ .x = 0, .y = 0, .width = base.width, .height = -base.height };
const dest = rl.Rectangle{ .x = 0, .y = 0, .width = screen.width, .height = screen.height };
const origin = rl.Vector2{ .x = 0, .y = 0 };
while (!rl.windowShouldClose()) {
rl.beginTextureMode(display);
{
rl.clearBackground(.black);
rl.drawText("Virtual", 18, 10, 36, .white);
rl.drawText("screen size", 22, 34, 20, .white);
rl.drawText("in Raylib", 22, 48, 27, .orange);
}
rl.endTextureMode();
rl.beginDrawing();
{
rl.clearBackground(.black);
rl.drawTexturePro(display.texture, source, dest, origin, 0, .white);
}
rl.endDrawing();
}
}
@peterhellberg

Copy link
Copy Markdown
Author
Screenshot_2026-05-01_22-00-58

@peterhellberg

Copy link
Copy Markdown
Author

I'm using these bindings to Raylib: https://github.com/raylib-zig/raylib-zig

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