enum Filter
type Filter* = enum {
nearest = 0
linear = 1
}
Filtering mode for images, render targets, and fonts.
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.
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.blit
fn (i: ^Image) blit*(src, dest: rect::Rect, color: uint32 = 0xFFFFFFFF, rot: th::fu = 0, origin: th::Vf2 = {0, 0}) {
Copies source rectangle (texture coordinates) to destination rectangle (screen coordinates).
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: Filter): 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.