opaque Image
type Image* = struct{ _: ^struct{} }
Represents a drawable image. It is an opaque structure. Images support a color filter. It is applied by multiplying the color of each pixel with the filter.
opaque RenderTarget
type RenderTarget* = struct { _: ^struct{} }
An image you can render to.
fn createRenderTarget
fn createRenderTarget*(size: th::Vf2, filter: int): (RenderTarget, std::Err) {
Creates a render target you can draw to, like to a window.
Filter specifies specfifies filtering for resulting image.
Image can be retrieved via toImage
.
fn RenderTarget.end
fn (rt: ^RenderTarget) begin*(): std::Err {
Begins the render target rendering pass.
fn RenderTarget.end
fn (rt: ^RenderTarget) end*(wp: th::Vf2): std::Err {
Ends the render target rendering pass.
fn RenderTarget.toImage
fn (rt: ^RenderTarget) toImage*(): Image {
Returns the image of the render target. The resulting image has the same
lifetime as the base RenderTarget. If you need to use it past the lifetime
of the RenderTarget, use the copy method.
Do not call setfilter
on the resulting image.
fn load
fn load*(path: str): (Image, std::Err) {
Loads an image at path.
fn Image.validate
fn (i: ^Image) validate*(): bool {
Returns true, if i's handle points to an image.
fn Image.flipv
fn (i: ^Image) flipv*(flip: bool) {
Flips image on it's vertical axis.
fn Image.fliph
fn (i: ^Image) fliph*(flip: bool) {
Flips image on it's horizontal axis.
fn Image.draw
fn (i: ^Image) draw*(t: th::Transform, color: uint32 = th::white) {
Draws the image in screen coordinates. It transforms it with t and applies color as a color filter.
fn Image.drawNinepatch
fn (i: ^Image) drawNinepatch*(outer, inner, dest: rect::Rect, color: uint32 = th::white, scale: real = 1.0) {
Draws "nine-patch" image.
outer
specifies the texture coordinates of the outer rect of source image,
inner
specifies coordinates of inner rect of source image, positioned relative to outer
.
You can tint with color
.
fn Image.drawOnQuad
fn (i: ^Image) drawOnQuad*(q: th::Quad, color: uint32 = th::white) {
Draws the image on top of a quad with corners of the image positioned on the verticies of the quad.
fn Image.getDims
fn (i: ^Image) getDims*(): th::Vf2 {
Returns width and heigth.
fn Image.crop
fn (i: ^Image) crop*(tl, br: th::Vf2) {
Crops an image. Coordinates are between 0, 0 (top left) and 1, 1 (bottom right)
fn Image.cropPx
fn (i: ^Image) cropPx*(tr, br: th::Vf2) {
Same as Image.crop
, but the positions are in pixels.
fn Image.cropRect
fn (i: ^Image) cropRect*(r: rect::Rect) {
Same as Image.crop
, but uses a rect instead of two positions.
fn Image.cropQuad
fn (i: ^Image) cropQuad*(q: th::Quad) {
Crop an image using a quad.
fn Image.getCropQuad
fn (i: ^Image) getCropQuad*(): th::Quad {
Crop an image using a quad.
fn mk
fn mk*(data: []uint32, dm: th::Vf2): (Image, std::Err) {
Creates an image from raw data.
fn Image.copy
fn (i: ^Image) copy*(): (Image, std::Err) {
Copies image into a new one.
fn Image.setfilter
fn (i: ^Image) setfilter*(filter: int): std::Err {
Sets a mag/min filter. 0 is nearest, others are linear. This function will regenerate the texture. This means it shouldn't be used in a loop. https://learnopengl.com/img/getting-started/texture_filtering.png left is nearest, right is linear.
fn Image.setData
fn (i: ^Image) setData*(data: []uint32, dm: th::Vf2): std::Err {
Updates the image data. dm are the dimensions of the new image. The new image doesn't have to be the same size as the old one.
fn Image.getData
fn (i: ^Image) getData*(): []uint32 {
Gets the image data. This downloads the data from the GPU on each call. Don't use in performance critical sections.