macroquad icon indicating copy to clipboard operation
macroquad copied to clipboard

clear background not working

Open paul-asvb opened this issue 3 years ago • 4 comments

maybe i am thinking about this wrong, but my expectation for this would be that the line would stay(not be cleared) after every frame. is this a wrong expectation?

use macroquad::prelude::*;

#[macroquad::main("game")]
async fn main() {
    let mut y = 100.0;

    loop {
        //clear_background(RED);
        draw_line(50.0, y, 250.0, y, 15.0, BLUE);
        y = y + 1.0;
        next_frame().await
    }
}

paul-asvb avatar Mar 18 '22 22:03 paul-asvb

Its a correct expectation, but, unfortunately, its not implemented :(

Unfortunately, some platforms do not really support this, and this should be a special case in macroquad. Macroquad should detect that no clear was used and switch from rendering to the screen to rendering to a buffer.

Probably the best solution - show some kind of a warning/error when clear got lost.

For details check this answer: https://stackoverflow.com/a/27353240

not-fl3 avatar Mar 19 '22 00:03 not-fl3

Or should i keep this open?

paul-asvb avatar Mar 21 '22 09:03 paul-asvb

It looks like a legit issue to me, lets's keep it open!

not-fl3 avatar Mar 21 '22 13:03 not-fl3

I'd say you should do clear_background() outside of the loop, so it only gets called once?

eboatwright avatar Mar 22 '22 18:03 eboatwright

Any update on this? I've been trying to find workarounds, but no sucess so far.

titoco3000 avatar Apr 10 '23 21:04 titoco3000

Any update on this? I've been trying to find workarounds, but no sucess so far.

a common workaround is to render into a texture and draw this texture each frame, while updating the texture's content only when required

not-fl3 avatar Apr 10 '23 22:04 not-fl3

And is there how to change the draw target for functions of the shapes module, so that it draw to a texture instead of the screen? Or do I have to do the per pixel manipulation of the texture?

titoco3000 avatar Apr 11 '23 19:04 titoco3000

Yes, you use a render target, this example might help: https://github.com/not-fl3/macroquad/blob/master/examples/post_processing.rs

not-fl3 avatar Apr 11 '23 20:04 not-fl3