Pixel render
This module defines a set of functions for rendering shapes and lines as pixel images (in Bitmap representation).
To add this module to your project, add the following line to your project file:
require engine.render.pixel_render // or require engine.core
Usage example:
var bitmap = Bitmap(100, 200)
// create a GPU texture with the bitmap content, using point sampling and no mipmaps for pixel graphics (it can be used in any material)
var texId = create_texture(bitmap, TextureDeclaration(filter = TextureFilter Point, generateMipLevels = false))
// draw a blue rectangle at position (0, 0) with width = 10 and height = 20
fill_rect(bitmap, 0, 0, 10, 20, 0xFF0400FF)
// use `update_texture(bitmap, texId)` to update the texture
Functions
fill_rect (var to_image: Bitmap; x: int; y: int; width: int; height: int; color: uint)
fill_rect (var to_image: Bitmap; x: float; y: float; width: float; height: float; color: uint)
fill_rect (var to_image: Bitmap; left_top: int2; size: int2; color: uint)
fill_rect (var to_image: Bitmap; left_top: float2; size: float2; color: uint)
rect (var to_image: Bitmap; x: int; y: int; width: int; height: int; color: uint)
rect (var to_image: Bitmap; x: float; y: float; width: float; height: float; color: uint)
rect (var to_image: Bitmap; left_top: int2; size: int2; color: uint)
rect (var to_image: Bitmap; left_top: float2; size: float2; color: uint)
set_pixel (var to_image: Bitmap; x: int; y: int; color: uint)
set_pixel (var to_image: Bitmap; x: float; y: float; color: uint)
line (var to_image: Bitmap; from: float2; to: float2; color: uint)
line (var to_image: Bitmap; from: int2; to: int2; color: uint)
line (var to_image: Bitmap; x1: int; y1: int; x2: int; y2: int; color: uint)
antialiased_line (var to_image: Bitmap; from: float2; to: float2; color: uint; line_width: float)
antialiased_line (var to_image: Bitmap; from: int2; to: int2; color: uint; line_width: float)
circle (var to_image: Bitmap; center: float2; radius: float; color: uint)
circle (var to_image: Bitmap; x: int; y: int; radius: int; color: uint)
circle (var to_image: Bitmap; center: int2; radius: int; color: uint)
circle (var to_image: Bitmap; x: float; y: float; radius: float; color: uint)
fill_circle (var to_image: Bitmap; center: float2; radius: float; color: uint)
fill_circle (var to_image: Bitmap; x: int; y: int; radius: int; color: uint)
fill_circle (var to_image: Bitmap; center: int2; radius: int; color: uint)
fill_circle (var to_image: Bitmap; x: float; y: float; radius: float; color: uint)
draw_text (var to_image: Bitmap; pos: int2; text: string; color: uint)
draw_text (var to_image: Bitmap; x: int; y: int; text: string; color: uint)
draw_text (var to_image: Bitmap; pos: float2; text: string; color: uint)
draw_text (var to_image: Bitmap; x: float; y: float; text: string; color: uint)
- copy_image_rect(to_image: Bitmap; source: Bitmap; to: int2; from: int2; size: int2; transparency: bool = false; tint_color: uint = 0xffffffff)
copies a rectangle from one image to another with optional transparency and tinting
- Arguments:
to_image : Bitmap - destination image
source : Bitmap - source image
to : int2 - destination position (top left corner)
from : int2 - source position (top left corner)
size : int2 - size of the rectangle (width, height)
transparency : bool - if true, the rectangle is drawn with transparency
tint_color : uint - color of the rectangle as an 0xAARRGGBB value (32-bit uint)
Usage example:
// copies a rectangle from (20, 40) in source image to (10, 30) in destination image with width 100 and height 200
copy_image_rect(pixel_buffer, source, int2(10, 30), int2(20, 40), int2(100, 200))
- fill_rect(to_image: Bitmap; x: int; y: int; width: int; height: int; color: uint)
fills a rectangle with a given color from the top left corner
- Arguments:
to_image : Bitmap - destination image
x : int - x coordinate of the top left corner of the rectangle
y : int - y coordinate of the top left corner of the rectangle
width : int - width of the rectangle
height : int - height of the rectangle
color : uint - color of the rectangle as an 0xAARRGGBB value (32-bit uint)
Usage example:
fill_rect(pixel_buffer, 10, 30, 100, 200, 0xFF0400FF) // draws a blue rectangle at (10, 30) with width 100 and height 200
- fill_rect(to_image: Bitmap; x: float; y: float; width: float; height: float; color: uint)
Usage example:
fill_rect(pixel_buffer, 10, 30, 100, 200.0, 0xFF0400FF) // draws a blue rectangle at (10, 30) with width 100 and height 200
- Arguments:
to_image : Bitmap
x : float
y : float
width : float
height : float
color : uint
- fill_rect(to_image: Bitmap; left_top: int2; size: int2; color: uint)
Usage example:
fill_rect(pixel_buffer, int2(10, 30), int2(100, 200), 0xFF0400FF) // draws a blue rectangle at (10, 30) with width 100 and height 200
- Arguments:
to_image : Bitmap
left_top : int2
size : int2
color : uint
- fill_rect(to_image: Bitmap; left_top: float2; size: float2; color: uint)
Usage example:
fill_rect(pixel_buffer, int2(10, 30), int2(100, 200), 0xFF0400FF) // draws a blue rectangle at (10, 30) with width 100 and height 200
- Arguments:
to_image : Bitmap
left_top : float2
size : float2
color : uint
- rect(to_image: Bitmap; x: int; y: int; width: int; height: int; color: uint)
draws a rectangle (without filling it) with a given color
- Arguments:
to_image : Bitmap - destination image
x : int - x coordinate of the top left corner of the rectangle
y : int - y coordinate of the top left corner of the rectangle
width : int - width of the rectangle
height : int - height of the rectangle
color : uint - color of the rectangle as an 0xAARRGGBB value (32-bit uint)
Usage example:
rect(pixel_buffer, 10, 30, 100, 200, 0xFF0400FF) // draws a blue rectangle (without filling it) at (10, 30) with width 100 and height 200
- rect(to_image: Bitmap; x: float; y: float; width: float; height: float; color: uint)
Usage example:
rect(pixel_buffer, 10, 30, 100, 200.0, 0xFF0400FF) // draws a blue rectangle (without filling it) at (10, 30) with width 100 and height 200
- Arguments:
to_image : Bitmap
x : float
y : float
width : float
height : float
color : uint
- rect(to_image: Bitmap; left_top: int2; size: int2; color: uint)
Usage example:
rect(pixel_buffer, int2(10, 30), int2(100, 200), 0xFF0400FF) // draws a blue rectangle (without filling it) at (10, 30) with width 100 and height 200
- Arguments:
to_image : Bitmap
left_top : int2
size : int2
color : uint
- rect(to_image: Bitmap; left_top: float2; size: float2; color: uint)
Usage example:
rect(pixel_buffer, int2(10, 30), float2(100.0, 200.0), 0xFF0400FF) // draws a blue rectangle (without filling it) at (10, 30) with width 100 and height 200
- Arguments:
to_image : Bitmap
left_top : float2
size : float2
color : uint
- set_pixel(to_image: Bitmap; x: int; y: int; color: uint)
sets a single pixel to a given color
- Arguments:
to_image : Bitmap - destination image
x : int - x coordinate of the pixel
y : int - y coordinate of the pixel
color : uint - color of the pixel as an 0xAARRGGBB value (32-bit uint)
Usage example:
set_pixel(pixel_buffer, 10, 30, 0xFF0400FF) // sets the pixel at (10, 30) to blue
- set_pixel(to_image: Bitmap; pos: int2; color: uint)
sets a single pixel to a given color
- Arguments:
to_image : Bitmap - destination image
pos : int2 - position of the pixel (x, y)
color : uint - color of the pixel as an 0xAARRGGBB value (32-bit uint)
Usage example:
set_pixel(pixel_buffer, int2(10, 30), 0xFF0400FF) // sets the pixel at (10, 30) to blue
- set_pixel(to_image: Bitmap; x: float; y: float; color: uint)
sets a single pixel to a given color
- Arguments:
to_image : Bitmap - destination image
x : float - x coordinate of the pixel
y : float - y coordinate of the pixel
color : uint - color of the pixel as an 0xAARRGGBB value (32-bit uint)
- set_pixel(to_image: Bitmap; pos: float2; color: uint)
sets a single pixel to a given color
- Arguments:
to_image : Bitmap - destination image
pos : float2 - position of the pixel (x, y)
color : uint - color of the pixel as an 0xAARRGGBB value (32-bit uint)
- line(to_image: Bitmap; from: float2; to: float2; color: uint)
draws a line from one point to another (coordinates will be floored as centers of pixels)
- Arguments:
to_image : Bitmap - destination image
from : float2 - starting point (x, y)
to : float2 - ending point (x, y)
color : uint - color of the line as an 0xAARRGGBB value (32-bit uint)
Usage example:
line(pixel_buffer, float2(10.0, 30.0), float2(100., 200.), 0xFF0400FF) // draws a blue line from (10, 30) to (100, 200)
- line(to_image: Bitmap; from: int2; to: int2; color: uint)
Usage example:
line(pixel_buffer, int2(10, 30), int2(100, 200), 0xFF0400FF) // draws a blue line from (10, 30) to (100, 200)
- Arguments:
to_image : Bitmap
from : int2
to : int2
color : uint
- line(to_image: Bitmap; x1: int; y1: int; x2: int; y2: int; color: uint)
Usage example:
line(pixel_buffer, 10, 30, 100, 200, 0xFF0400FF) // draws a blue line from (10, 30) to (100, 200)
- Arguments:
to_image : Bitmap
x1 : int
y1 : int
x2 : int
y2 : int
color : uint
- antialiased_line(to_image: Bitmap; from: float2; to: float2; color: uint; line_width: float)
Draws a line from one point to another (coordinates will be floored as center of the pixels) This line has width and anti-aliased
- Arguments:
to_image : Bitmap - destination image
from : float2 - starting point (x, y)
to : float2 - ending point (x, y)
color : uint - color of the line as an 0xAARRGGBB value (32-bit uint)
line_width : float - width of the line
Usage example:
line(pixel_buffer, float2(10.0, 30.0), float2(100.0, 200.0), 0xFF0400FF, 10.0) // draws a blue line from (10, 30) to (100, 200) 10-pixel width
- antialiased_line(to_image: Bitmap; from: int2; to: int2; color: uint; line_width: float)
Usage example:
antialiased_line(pixel_buffer, int2(10, 30), int2(100, 200), 0xFF0400FF, 10.0) // draws a blue line from (10, 30) to (100, 200) 10-pixel width
- Arguments:
to_image : Bitmap
from : int2
to : int2
color : uint
line_width : float
- antialiased_line(to_image: Bitmap; x1: int; y1: int; x2: int; y2: int; color: uint; line_width: float)
Usage example:
antialiased_line(pixel_buffer, 10, 30, 100, 200, 0xFF0400FF, 10.0) // draws a blue line from (10, 30) to (100, 200) 10-pixel width
- Arguments:
to_image : Bitmap
x1 : int
y1 : int
x2 : int
y2 : int
color : uint
line_width : float
- antialiased_line(to_image: Bitmap; x1: float; y1: float; x2: float; y2: float; color: uint; line_width: float)
Usage example:
antialiased_line(pixel_buffer, 10.0, 30.0, 100.0, 200.0, 0xFF0400FF, 10.0) // draws a blue line from (10, 30) to (100, 200) 10-pixel width
- Arguments:
to_image : Bitmap
x1 : float
y1 : float
x2 : float
y2 : float
color : uint
line_width : float
- circle(to_image: Bitmap; center: float2; radius: float; color: uint)
draws a border of a circle with center and radius (coordinates will be floored as centers of pixels)
- Arguments:
to_image : Bitmap - destination image
center : float2 - center of the circle (x, y)
radius : float - radius of the circle
color : uint - color of the circle as an 0xAARRGGBB value (32-bit uint)
Usage example:
circle(pixel_buffer, float2(100.0, 200.0), 50., 0xFF0400FF) // draws a blue circle with center at (100, 200) and radius 50
- circle(to_image: Bitmap; x: int; y: int; radius: int; color: uint)
Usage example:
circle(pixel_buffer, 100, 200, 50, 0xFF0400FF) // draws a blue circle with center at (100, 200) and radius 50
- Arguments:
to_image : Bitmap
x : int
y : int
radius : int
color : uint
- circle(to_image: Bitmap; center: int2; radius: int; color: uint)
Usage example:
circle(pixel_buffer, int2(100, 200), 50, 0xFF0400FF) // draws a blue circle with center at (100, 200) and radius 50
- Arguments:
to_image : Bitmap
center : int2
radius : int
color : uint
- circle(to_image: Bitmap; x: float; y: float; radius: float; color: uint)
Usage example:
circle(pixel_buffer, 100.0, 200.0, 50.0, 0xFF0400FF) // draws a blue circle with center at (100, 200) and radius 50
- Arguments:
to_image : Bitmap
x : float
y : float
radius : float
color : uint
- fill_circle(to_image: Bitmap; center: float2; radius: float; color: uint)
fills a circle with a given color (center and radius will be floored as centers of pixels)
- Arguments:
to_image : Bitmap - destination image
center : float2 - center of the circle (x, y)
radius : float - radius of the circle
color : uint - color of the circle as an 0xAARRGGBB value (32-bit uint)
Usage example:
fill_circle(pixel_buffer, float2(100.0, 200.0), 50.0, 0xFF0400FF) // fills a blue circle with center at (100, 200) and radius 50
- fill_circle(to_image: Bitmap; x: int; y: int; radius: int; color: uint)
Usage example:
fill_circle(pixel_buffer, 100, 200, 50, 0xFF0400FF) // fills a blue circle with center at (100, 200) and radius 50
- Arguments:
to_image : Bitmap
x : int
y : int
radius : int
color : uint
- fill_circle(to_image: Bitmap; center: int2; radius: int; color: uint)
Usage example:
fill_circle(pixel_buffer, int2(100, 200), 50, 0xFF0400FF) // fills a blue circle with center at (100, 200) and radius 50
- Arguments:
to_image : Bitmap
center : int2
radius : int
color : uint
- fill_circle(to_image: Bitmap; x: float; y: float; radius: float; color: uint)
Usage example:
fill_circle(pixel_buffer, 100.0, 200.0, 50.0, 0xFF0400FF) // fills a blue circle with center at (100, 200) and radius 50
- Arguments:
to_image : Bitmap
x : float
y : float
radius : float
color : uint
- draw_text(to_image: Bitmap; pos: int2; text: string; color: uint)
draws a text at a given position with a given color (uses 8x16 pixel font)
- Arguments:
to_image : Bitmap - destination image
pos : int2 - position of the text int2(x, y)
text : string - text to draw
color : uint - color of the text as an 0xAARRGGBB value (32-bit uint)
Usage example:
draw_text(pixel_buffer, int2(10, 30), "Hello, World!", 0xFF0400FF) // draws a blue text "Hello, World!" at (10, 30)
- draw_text(to_image: Bitmap; x: int; y: int; text: string; color: uint)
Usage example:
draw_text(pixel_buffer, 10, 30, "Hello, World!", 0xFF0400FF) // draws a blue text "Hello, World!" at (10, 30)
- Arguments:
to_image : Bitmap
x : int
y : int
text : string
color : uint
- draw_text(to_image: Bitmap; pos: float2; text: string; color: uint)
Usage example:
draw_text(pixel_buffer, float2(10.0, 30.0), "Hello, World!", 0xFF0400FF) // draws a blue text "Hello, World!" at (10, 30)
- Arguments:
to_image : Bitmap
pos : float2
text : string
color : uint
- draw_text(to_image: Bitmap; x: float; y: float; text: string; color: uint)
Usage example:
draw_text(pixel_buffer, 10.0, 30.0, "Hello, World!", 0xFF0400FF) // draws a blue text "Hello, World!" at (10, 30)
- Arguments:
to_image : Bitmap
x : float
y : float
text : string
color : uint