QuantumBadger / Speedy2D

Rust library for hardware accelerated drawing of 2D shapes, images, and text, with an easy to use API.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Drawing to an image

superlou opened this issue · comments

After some discussion in #88, a mechanism to allow users to cheaply scale the canvas up or down would be to allow an API for drawing to an ImageHandle, which could then be scaled using hardware acceleration. From the discussion, this was where we were heading:

pub fn draw_to_image(
    &mut self,
    image: &ImageHandle,
    operations: FnOnce(&mut Graphics2D)
)

// So to draw a rectangle to an image, you'd call it as follows (in on_draw()):
// The operations done in the closure would apply to the image, rather than the main window.
graphics.draw_to_image(&image, |graphics| {
    graphics.draw_rectangle(...);
});

Then, use draw_rectangle_image(...) to draw the image into a scaled/positioned rectangle. This would also require adding a function to create an empty image/texture.