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 {
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*() {
Begins the render target rendering pass.
fn RenderTarget.end
fn (rt: ^RenderTarget) end*(wp: th.Vf2) {
Ends the render target rendering pass.
fn RenderTarget.toImage
fn (rt: ^RenderTarget) toImage*(): Image {
Returns the image of the render target.
Do not call setfilter
on the resulting image.
fn load
fn load*(path: str): Image {
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 {
Creates an image from raw data.
fn Image.copy
fn (i: ^Image) copy*(): Image {
Copies image into a new one.
fn Image.setfilter
fn (i: ^Image) setfilter*(filter: int) {
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) {
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.