Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Metal backend with high_dpi = false #446

Merged
merged 1 commit into from
Jun 13, 2024

Conversation

birhburh
Copy link
Contributor

Example code

use macroquad::prelude::*;

fn window_conf() -> Conf {
    Conf {
        window_title: "Heavy Metal Example".to_owned(),
        platform: miniquad::conf::Platform {
            blocking_event_loop: true,
            apple_gfx_api: miniquad::conf::AppleGfxApi::Metal,
            ..Default::default()
        },
        // high_dpi: true,
        ..Default::default()
    }
}

#[macroquad::main(window_conf)]
async fn main() {
    macroquad::miniquad::window::schedule_update();
    loop {
        clear_background(LIGHTGRAY);
        draw_line(
            0.,
            screen_height() / 2.,
            screen_width(),
            screen_height() / 2.,
            2.,
            BLACK,
        );
        draw_line(
            screen_width() / 2.,
            0.,
            screen_width() / 2.,
            screen_height(),
            2.,
            BLACK,
        );

        let rect_width = screen_width() / 2. - 2.;
        let rect_height = screen_height() / 2. - 2.;

        let font_size = 72.;
        {
            let text = "1";
            let text_size = measure_text(text, None, font_size as _, 1.0);

            draw_text(
                text,
                rect_width / 2. - text_size.width / 2.,
                rect_height / 2. + text_size.height / 2.,
                font_size,
                RED,
            );
        }
        {
            let text = "2";
            let text_size = measure_text(text, None, font_size as _, 1.0);

            draw_text(
                text,
                rect_width + rect_width / 2. - text_size.width / 2.,
                rect_height / 2. + text_size.height / 2.,
                font_size,
                GREEN,
            );
        }
        {
            let text = "3";
            let text_size = measure_text(text, None, font_size as _, 1.0);

            draw_text(
                text,
                rect_width / 2. - text_size.width / 2.,
                rect_height + rect_height / 2. + text_size.height / 2.,
                font_size,
                BLUE,
            );
        }
        {
            let text = "4";
            let text_size = measure_text(text, None, font_size as _, 1.0);

            draw_text(
                text,
                rect_width + rect_width / 2. - text_size.width / 2.,
                rect_height + rect_height / 2. + text_size.height / 2.,
                font_size,
                BLACK,
            );
        }
        next_frame().await
    }
}

For Metal/high_dpi=false it looked like this:
Screenshot 2024-06-12 at 04 09 43

For other combinations (Opengl/high_dpi=false, Opengl/high_dpi=true, Metal/high_dpi=true) it looked like this:
Screenshot 2024-06-12 at 04 07 28

Now it looks as above for Metal/high_dpi=false also

@not-fl3 not-fl3 merged commit f6780f1 into not-fl3:master Jun 13, 2024
10 checks passed
@not-fl3
Copy link
Owner

not-fl3 commented Jun 13, 2024

Thanks for all your PRs, great work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants