Function macroquad::texture::draw_texture_ex
source ยท pub fn draw_texture_ex(
texture: &Texture2D,
x: f32,
y: f32,
color: Color,
params: DrawTextureParams,
)
Examples found in repository?
examples/screen_texture.rs (lines 21-30)
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
async fn main() {
let texture: Texture2D = load_texture("examples/chess.png").await.unwrap();
let lens_material = load_material(
ShaderSource::Glsl {
vertex: LENS_VERTEX_SHADER,
fragment: LENS_FRAGMENT_SHADER,
},
MaterialParams {
uniforms: vec![UniformDesc::new("Center", UniformType::Float2)],
..Default::default()
},
)
.unwrap();
loop {
clear_background(WHITE);
draw_texture_ex(
&texture,
0.0,
0.0,
WHITE,
DrawTextureParams {
dest_size: Some(vec2(screen_width(), screen_height())),
..Default::default()
},
);
let lens_center = mouse_position();
lens_material.set_uniform("Center", lens_center);
gl_use_material(&lens_material);
draw_circle(lens_center.0, lens_center.1, 250.0, RED);
gl_use_default_material();
next_frame().await
}
}
More examples
examples/post_processing.rs (lines 39-48)
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
async fn main() {
let render_target = render_target(320, 150);
render_target.texture.set_filter(FilterMode::Nearest);
let material = load_material(
ShaderSource::Glsl {
vertex: CRT_VERTEX_SHADER,
fragment: CRT_FRAGMENT_SHADER,
},
Default::default(),
)
.unwrap();
loop {
// drawing to the texture
// 0..100, 0..100 camera
set_camera(&Camera2D {
zoom: vec2(0.01, 0.01),
target: vec2(0.0, 0.0),
render_target: Some(render_target.clone()),
..Default::default()
});
clear_background(LIGHTGRAY);
draw_line(-30.0, 45.0, 30.0, 45.0, 3.0, BLUE);
draw_circle(-45.0, -35.0, 20.0, YELLOW);
draw_circle(45.0, -35.0, 20.0, GREEN);
// drawing to the screen
set_default_camera();
clear_background(WHITE);
gl_use_material(&material);
draw_texture_ex(
&render_target.texture,
0.,
0.,
WHITE,
DrawTextureParams {
dest_size: Some(vec2(screen_width(), screen_height())),
..Default::default()
},
);
gl_use_default_material();
next_frame().await;
}
}
examples/letterbox.rs (lines 57-67)
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
async fn main() {
// Setup 'render_target', used to hold the rendering result so we can resize it
let render_target = render_target_msaa(VIRTUAL_WIDTH as u32, VIRTUAL_HEIGHT as u32, 4);
render_target.texture.set_filter(FilterMode::Linear);
// Setup camera for the virtual screen, that will render to 'render_target'
let mut render_target_cam =
Camera2D::from_display_rect(Rect::new(0., 0., VIRTUAL_WIDTH, VIRTUAL_HEIGHT));
render_target_cam.render_target = Some(render_target.clone());
loop {
// Get required scaling value
let scale: f32 = f32::min(
screen_width() / VIRTUAL_WIDTH,
screen_height() / VIRTUAL_HEIGHT,
);
// Mouse position in the virtual screen
let virtual_mouse_pos = Vec2 {
x: (mouse_position().0 - (screen_width() - (VIRTUAL_WIDTH * scale)) * 0.5) / scale,
y: (mouse_position().1 - (screen_height() - (VIRTUAL_HEIGHT * scale)) * 0.5) / scale,
};
// ------------------------------------------------------------------------
// Begin drawing the virtual screen to 'render_target'
// ------------------------------------------------------------------------
set_camera(&render_target_cam);
clear_background(LIGHTGRAY);
draw_text("Hello Letterbox", 20.0, 20.0, 30.0, DARKGRAY);
draw_circle(VIRTUAL_WIDTH / 2.0 - 65.0, VIRTUAL_HEIGHT / 2.0, 35.0, RED);
draw_circle(VIRTUAL_WIDTH / 2.0 + 65.0, VIRTUAL_HEIGHT / 2.0, 35.0, BLUE);
draw_circle(
VIRTUAL_WIDTH / 2.0,
VIRTUAL_HEIGHT / 2.0 - 65.0,
35.0,
YELLOW,
);
draw_circle(virtual_mouse_pos.x, virtual_mouse_pos.y, 15.0, BLACK);
// ------------------------------------------------------------------------
// Begin drawing the window screen
// ------------------------------------------------------------------------
set_default_camera();
clear_background(BLACK); // Will be the letterbox color
// Draw 'render_target' to window screen, porperly scaled and letterboxed
draw_texture_ex(
&render_target.texture,
(screen_width() - (VIRTUAL_WIDTH * scale)) * 0.5,
(screen_height() - (VIRTUAL_HEIGHT * scale)) * 0.5,
WHITE,
DrawTextureParams {
dest_size: Some(vec2(VIRTUAL_WIDTH * scale, VIRTUAL_HEIGHT * scale)),
flip_y: true, // Must flip y otherwise 'render_target' will be upside down
..Default::default()
},
);
next_frame().await;
}
}