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

Drawing a translucent rectangle over an opaque background causes the background to become translucent #843

Open
pontaoski opened this issue Oct 16, 2024 · 0 comments · May be fixed by #849

Comments

@pontaoski
Copy link

The translucent rectangle should be alpha-composited onto the background, not make it translucent in turn.

Reproduction: https://github.com/pontaoski/macroquad-reproduction, cargo run --bin translucency

use macroquad::prelude::*;

#[macroquad::main("Translucency")]
async fn main() {
    let target = render_target(8, 8);
    let mut cam = Camera2D::from_display_rect(Rect::new(0., 0., 8., 8.));
    cam.render_target = Some(target.clone());
    let tile = Texture2D::from_file_with_format(include_bytes!("tile.png"), None);
    let checkerboard = Texture2D::from_file_with_format(include_bytes!("checkerboard.png"), None);

	loop {
		set_camera(&cam);
		clear_background(WHITE);
		draw_texture(&tile, 0., 0., WHITE);
		draw_rectangle(0., 0., 8., 8., Color::new(0., 0., 0., 0.2));

		set_default_camera();
		clear_background(WHITE);
		draw_texture_ex(&checkerboard, 0., 0., WHITE, DrawTextureParams { dest_size: Some(Vec2::new(screen_width(), screen_height())), ..Default::default() });

		draw_texture_ex(&target.texture, 0., 0., WHITE, DrawTextureParams { dest_size: Some(Vec2::new(screen_width(), screen_height())), ..Default::default() });

		next_frame().await;
	}
}
@pontaoski pontaoski linked a pull request Oct 20, 2024 that will close this issue
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 a pull request may close this issue.

1 participant