You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
screen_dpi_scale() // returns 1.0
If multiply screen size on 2.0 all works like need, but why?
use macroquad::prelude::{
clear_background, draw_rectangle, draw_rectangle_lines, next_frame, screen_height,
screen_width, set_camera, vec2, Camera2D, Vec2, BLACK, BLUE,
};
#[macroquad::main("Playground")]
async fn main() {
let mut camera = Camera2D {
target: Vec2::ZERO,
..Default::default()
};
let mut zoom = 1.0;
loop {
clear_background(BLACK);
let (w, h) = (screen_width(), screen_height()); // multiply on 2.0 - all ok
camera.zoom = vec2(zoom / screen_width(), zoom / screen_height());
set_camera(&camera);
draw_rectangle_lines(-w / 2., -h / 2., w, h, 5., BLUE);
next_frame().await;
}
}
The text was updated successfully, but these errors were encountered:
historydev
changed the title
Why is the rectangle half the size of the window when using screen_width() and screen_height()?
Why is the rectangle half the size of the window when using screen_width() and screen_height() or similar size in scalar values?
Feb 1, 2025
historydev
changed the title
Why is the rectangle half the size of the window when using screen_width() and screen_height() or similar size in scalar values?
Why is the rectangle half the size of the window?
Feb 1, 2025
Macro-quads uses OpenGL for rendering - which is why this might be unexpected behavior.
OpenGL uses something called "normalized coordinates" which ranges them from -1 to 1. So the left part of the screen is -1 and the right part is 1. This makes it easy to express the center of 0. Ths distance between -1 and 1 is what is scaled by your "zoom" factor - which is why you see exactly double the size of the screen.
Internally macroquad seems to use GLAM which uses the established glOrtho. My matrix math is a bit rusty (pun very much intended) but I believe the 2 in the formula you see is the cause of your confusion.
System: win11
screen_dpi_scale() // returns 1.0
If multiply screen size on 2.0 all works like need, but why?
The text was updated successfully, but these errors were encountered: