I have a weird use case for piston2d-graphics, where I'm making draw calls without a game loop, because I'm generating a batch of one-off images in a headless OpenGL context. The problem is that, given a glutin::HeadlessContext with dimensions widthxheight, I don't know how to construct a graphics::Viewport that covers exactly that rectangle.
For clarity, here's where my code diverges from regular code. Where a lot of sample code suggests something like
letmut glgraphics = GlGraphics::new(opengl);letmut events = Events::new(EventSettings::new());whileletSome(e) = events.next(&mut window){ifletSome(args) = e.render_args(){
glgraphics.draw(e.viewport(), |c, g| {
something.draw(c.transform, g);});}I instead use code like this, because I don't have a window or event loop:
letmut glgraphics = GlGraphics::new(opengl);let viewport = Viewport{rect:[0,0, width, height],// pretty sure this is wrong!draw_size:[width asu32, height asu32],window_size:[width asu32, height asu32],};for _ insome_iterator(){
glgraphics.draw(&viewport, |c, g| {/* what I'd like to write is graphics::image(&some_texture, c.transform, g); but to make sure my viewport coordinates are sensible I currently write */
graphics::Rectangle::new([1.0,1.0,1.0,1.0]).draw([0.0,0.0,1000.0,1000.0],&c.draw_state, c.transform, g);// and, spoiler, they're not});}The resulting image shows the square stretched out of shape, and partially off the horizontal edge it should be aligned to, and I'm pretty sure it's the result of my initial viewport dimensions being wrong.
I have a weird use case for piston2d-graphics, where I'm making draw calls without a game loop, because I'm generating a batch of one-off images in a headless OpenGL context. The problem is that, given a
glutin::HeadlessContextwith dimensionswidthxheight, I don't know how to construct a graphics::Viewport that covers exactly that rectangle.For clarity, here's where my code diverges from regular code. Where a lot of sample code suggests something like
I instead use code like this, because I don't have a window or event loop:
The resulting image shows the square stretched out of shape, and partially off the horizontal edge it should be aligned to, and I'm pretty sure it's the result of my initial viewport dimensions being wrong.