Macroquad how to draw to texture

Is there a way in macroquad to draw to a texture? I want to kind of draw a background which does not need to be redrawn every time, but could be drawn from some kind of buffer texture from time to time.

I tried something like

        set_camera(&self.camera);
        clear_background(RED);
        // draw stuff to the texture

        set_default_camera();
        draw_texture(self.render_target.texture, 0., 0., WHITE);
        //draw something that is changed every time

the camera itself is created with

        obj.camera = Camera2D {

        zoom: vec2(2.0 / screen_width() as f32, -2.0 / screen_height() as f32),

        target: vec2(screen_width() / 2.0, screen_height() / 2.0),

        //viewport: Some((0, 0, screen_width() as i32, screen_height() as i32)),

        render_target: Some(obj.render_target),

        ..Default::default()

but the texture is either not drawn to, or is not drawn.

Has someone an example for this, how this can be done?

kr

Btw, since this is a question about a rather specific library, you are more likely to get better answers in the forums specific to that library.
For your case, the forum links are given here.

1 Like

I was searching for that. But I have only seen a discord, which I have issues to enter into. But I will take another look.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.