Created
May 1, 2026 20:02
-
-
Save peterhellberg/2ff78303715d411ae31260a92fe7c1c5 to your computer and use it in GitHub Desktop.
Virtual screen size in Raylib-Zig
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
commented
May 1, 2026
Author
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