ggez Rectangle doesn't show up on canvas

154 Views Asked by At

I am trying to draw some black rectangles on a white canvas with ggez. I've looked at the Generative Art example that's linked at in the ggez docs.

My problem is, I'm not getting the rectangles to show up, all I get is a white canvas. I've debugged this to see if it correctly enters the draw branch and it does, so I guess there must be an issue with how I use ggez.

    fn draw(&mut self, ctx: &mut ggez::Context) -> GameResult {
        let mut canvas = graphics::Canvas::from_frame(ctx, Color::WHITE);

        for i in 0..GRID_SIZE.0 {
            for j in 0..GRID_SIZE.1 {
                if self.grid[i][j] {
                    let rect = Mesh::new_rectangle(
                        ctx,
                        DrawMode::fill(),
                        Rect::new(
                            i as f32 * CELL_SIZE.0,
                            j as f32 * CELL_SIZE.1,
                            CELL_SIZE.0,
                            CELL_SIZE.1,
                        ),
                        Color::BLACK,
                    )?;
                    canvas.draw(&rect, DrawParam::default());
                }
            }
        }

        canvas.finish(ctx)?;
        Ok(())
    }

1

There are 1 best solutions below

0
On BEST ANSWER

Apparently there is a problem when using ggez v0.8.1 with newer rust compilers (1.70.0 in my case). Using v0.9.0-rc0 of ggez has fixed my problem with rectangles not showing up.

The corresponding issue on the ggez repo can be found here.