(premise: the (pseudo) code is in Rust, however, answers in any language are accepted, since the Rust SDL library mimics closely the standard one).
I have a very minimal SDL2 template I use when I need to draw an image, display it (in a maximized window), and wait for a keypress.
The current logic works, however, it has a niggle: after the window is maximized (and the canvas updated), if I resize the window, redrawing doesn't occur.
This is my current pseudo-code:
let sdl_context = sdl2::init().unwrap();
let window = sdl_context
.video()
.unwrap()
.window(""window_title"", width as u32, height as u32)
.maximized()
.position_centered()
.resizable()
.build()
.unwrap();
let mut event_pump = sdl_context.event_pump().unwrap();
let mut canvas = window.into_canvas().present_vsync().build().unwrap();
canvas.set_logical_size(640, 480).unwrap();
// Needed to redraw, as the window has been maximized above.
//
event_pump.pump_events();
////////////////////////////////////////
// Here some pixels are drawn.
////////////////////////////////////////
canvas.present();
// Wait for a keypress or quit event.
//
for event in event_pump.wait_iter() {
match event {
Event::KeyDown { .. } => std::process::exit(0),
Event::KeyUp { .. } => std::process::exit(0),
Event::Quit { .. } => std::process::exit(0),
_ => {}
}
}
If I run this code, and resize the window without pressing any key (or quitting), the canvas doesn't redraw.
How should I change the code to make it redraw?
(note that I'm not using textures, because they were making the code more complex, and in the cases I use this template for, either speed is not a concern or there isn't a measurable speed improvement)