Open StayWithMeSenpai opened 1 year ago
This issue only seems to happen when drawing on the Canvas
Can you short self-contained example where this happens please? We can't help you unless we have more info.
WindowCanvas is an alias of Canvas
I had the same issue and while writing up an example I also stumbled upon what could be wrong.
TLDR; It wont work if the canvas has the underlying pixel format PixelFormatEnum::RGB24
Here is what I am trying to do in the code below:
Make a surface from the canvas
// Load bmp and convert to correct pixel format so that it can be blit_scaled
let wall_surface_bmp: Surface = sdl2::image::LoadSurface::from_file("assets/52.bmp").expect("Could not load bmp");
let mut wall_surface = Surface::new(wall_surface_bmp.width(), wall_surface_bmp.height(), PixelFormatEnum::RGB24).expect("Could not create wall surface");
wall_surface_bmp.blit(None, &mut wall_surface, None);
let mut wall_canvas = wall_surface.into_canvas().expect("Failed to make wall surface into canvas");
// This part works
wall_canvas.set_draw_color(Color::RGB(0, 0, 255));
wall_canvas.fill_rect(Rect::new(10, 10, 20, 20));
// None of these work
wall_canvas.set_draw_color(Color::RGB(0, 255, 0));
wall_canvas.draw_line(Point::new(0, 0), Point::new(32, 32));
wall_canvas.draw_point(Point::new(5, 5));
wall_canvas.draw_rect(Rect::new(10, 10, 20, 20));
wall_surface = wall_canvas.into_surface();
I tried two things where drawing to the canvas worked as intended:
The error seems to happen when trying to draw to a canvas with pixel format PixelFormatEnum::RGB24
Sounds like a problem with sdl2 directly and not this binding library, can you reproduce this in C?
The rect above renders correctly, but the line below it doesn't.
It doesn't even warn or error, just doesn't draw.