.. _stdlib_pixel_render: ============ 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 +++++++++ * :ref:`copy_image_rect (var to_image: Bitmap; source: Bitmap; to: int2; from: int2; size: int2; transparency: bool = false; tint_color: uint = 0xffffffff) ` * :ref:`fill_rect (var to_image: Bitmap; x: int; y: int; width: int; height: int; color: uint) ` * :ref:`fill_rect (var to_image: Bitmap; x: float; y: float; width: float; height: float; color: uint) ` * :ref:`fill_rect (var to_image: Bitmap; left_top: int2; size: int2; color: uint) ` * :ref:`fill_rect (var to_image: Bitmap; left_top: float2; size: float2; color: uint) ` * :ref:`rect (var to_image: Bitmap; x: int; y: int; width: int; height: int; color: uint) ` * :ref:`rect (var to_image: Bitmap; x: float; y: float; width: float; height: float; color: uint) ` * :ref:`rect (var to_image: Bitmap; left_top: int2; size: int2; color: uint) ` * :ref:`rect (var to_image: Bitmap; left_top: float2; size: float2; color: uint) ` * :ref:`set_pixel (var to_image: Bitmap; x: int; y: int; color: uint) ` * :ref:`set_pixel (var to_image: Bitmap; pos: int2; color: uint) ` * :ref:`set_pixel (var to_image: Bitmap; x: float; y: float; color: uint) ` * :ref:`set_pixel (var to_image: Bitmap; pos: float2; color: uint) ` * :ref:`line (var to_image: Bitmap; from: float2; to: float2; color: uint) ` * :ref:`line (var to_image: Bitmap; from: int2; to: int2; color: uint) ` * :ref:`line (var to_image: Bitmap; x1: int; y1: int; x2: int; y2: int; color: uint) ` * :ref:`antialiased_line (var to_image: Bitmap; from: float2; to: float2; color: uint; line_width: float) ` * :ref:`antialiased_line (var to_image: Bitmap; from: int2; to: int2; color: uint; line_width: float) ` * :ref:`antialiased_line (var to_image: Bitmap; x1: int; y1: int; x2: int; y2: int; color: uint; line_width: float) ` * :ref:`antialiased_line (var to_image: Bitmap; x1: float; y1: float; x2: float; y2: float; color: uint; line_width: float) ` * :ref:`circle (var to_image: Bitmap; center: float2; radius: float; color: uint) ` * :ref:`circle (var to_image: Bitmap; x: int; y: int; radius: int; color: uint) ` * :ref:`circle (var to_image: Bitmap; center: int2; radius: int; color: uint) ` * :ref:`circle (var to_image: Bitmap; x: float; y: float; radius: float; color: uint) ` * :ref:`fill_circle (var to_image: Bitmap; center: float2; radius: float; color: uint) ` * :ref:`fill_circle (var to_image: Bitmap; x: int; y: int; radius: int; color: uint) ` * :ref:`fill_circle (var to_image: Bitmap; center: int2; radius: int; color: uint) ` * :ref:`fill_circle (var to_image: Bitmap; x: float; y: float; radius: float; color: uint) ` * :ref:`draw_text (var to_image: Bitmap; pos: int2; text: string; color: uint) ` * :ref:`draw_text (var to_image: Bitmap; x: int; y: int; text: string; color: uint) ` * :ref:`draw_text (var to_image: Bitmap; pos: float2; text: string; color: uint) ` * :ref:`draw_text (var to_image: Bitmap; x: float; y: float; text: string; color: uint) ` .. _function-pixel_render_copy_image_rect_Bitmap_Bitmap_int2_int2_int2_bool_uint: .. das:function:: 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** : :ref:`Bitmap ` - destination image * **source** : :ref:`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)) .. _function-pixel_render_fill_rect_Bitmap_int_int_int_int_uint: .. das:function:: 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** : :ref:`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 .. _function-pixel_render_fill_rect_Bitmap_float_float_float_float_uint: .. das:function:: 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** : :ref:`Bitmap ` * **x** : float * **y** : float * **width** : float * **height** : float * **color** : uint .. _function-pixel_render_fill_rect_Bitmap_int2_int2_uint: .. das:function:: 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** : :ref:`Bitmap ` * **left_top** : int2 * **size** : int2 * **color** : uint .. _function-pixel_render_fill_rect_Bitmap_float2_float2_uint: .. das:function:: 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** : :ref:`Bitmap ` * **left_top** : float2 * **size** : float2 * **color** : uint .. _function-pixel_render_rect_Bitmap_int_int_int_int_uint: .. das:function:: 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** : :ref:`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 .. _function-pixel_render_rect_Bitmap_float_float_float_float_uint: .. das:function:: 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** : :ref:`Bitmap ` * **x** : float * **y** : float * **width** : float * **height** : float * **color** : uint .. _function-pixel_render_rect_Bitmap_int2_int2_uint: .. das:function:: 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** : :ref:`Bitmap ` * **left_top** : int2 * **size** : int2 * **color** : uint .. _function-pixel_render_rect_Bitmap_float2_float2_uint: .. das:function:: 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** : :ref:`Bitmap ` * **left_top** : float2 * **size** : float2 * **color** : uint .. _function-pixel_render_set_pixel_Bitmap_int_int_uint: .. das:function:: set_pixel(to_image: Bitmap; x: int; y: int; color: uint) sets a single pixel to a given color :Arguments: * **to_image** : :ref:`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 .. _function-pixel_render_set_pixel_Bitmap_int2_uint: .. das:function:: set_pixel(to_image: Bitmap; pos: int2; color: uint) sets a single pixel to a given color :Arguments: * **to_image** : :ref:`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 .. _function-pixel_render_set_pixel_Bitmap_float_float_uint: .. das:function:: set_pixel(to_image: Bitmap; x: float; y: float; color: uint) sets a single pixel to a given color :Arguments: * **to_image** : :ref:`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) .. _function-pixel_render_set_pixel_Bitmap_float2_uint: .. das:function:: set_pixel(to_image: Bitmap; pos: float2; color: uint) sets a single pixel to a given color :Arguments: * **to_image** : :ref:`Bitmap ` - destination image * **pos** : float2 - position of the pixel (x, y) * **color** : uint - color of the pixel as an 0xAARRGGBB value (32-bit uint) .. _function-pixel_render_line_Bitmap_float2_float2_uint: .. das:function:: 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** : :ref:`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) .. _function-pixel_render_line_Bitmap_int2_int2_uint: .. das:function:: 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** : :ref:`Bitmap ` * **from** : int2 * **to** : int2 * **color** : uint .. _function-pixel_render_line_Bitmap_int_int_int_int_uint: .. das:function:: 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** : :ref:`Bitmap ` * **x1** : int * **y1** : int * **x2** : int * **y2** : int * **color** : uint .. _function-pixel_render_antialiased_line_Bitmap_float2_float2_uint_float: .. das:function:: 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** : :ref:`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 .. _function-pixel_render_antialiased_line_Bitmap_int2_int2_uint_float: .. das:function:: 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** : :ref:`Bitmap ` * **from** : int2 * **to** : int2 * **color** : uint * **line_width** : float .. _function-pixel_render_antialiased_line_Bitmap_int_int_int_int_uint_float: .. das:function:: 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** : :ref:`Bitmap ` * **x1** : int * **y1** : int * **x2** : int * **y2** : int * **color** : uint * **line_width** : float .. _function-pixel_render_antialiased_line_Bitmap_float_float_float_float_uint_float: .. das:function:: 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** : :ref:`Bitmap ` * **x1** : float * **y1** : float * **x2** : float * **y2** : float * **color** : uint * **line_width** : float .. _function-pixel_render_circle_Bitmap_float2_float_uint: .. das:function:: 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** : :ref:`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 .. _function-pixel_render_circle_Bitmap_int_int_int_uint: .. das:function:: 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** : :ref:`Bitmap ` * **x** : int * **y** : int * **radius** : int * **color** : uint .. _function-pixel_render_circle_Bitmap_int2_int_uint: .. das:function:: 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** : :ref:`Bitmap ` * **center** : int2 * **radius** : int * **color** : uint .. _function-pixel_render_circle_Bitmap_float_float_float_uint: .. das:function:: 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** : :ref:`Bitmap ` * **x** : float * **y** : float * **radius** : float * **color** : uint .. _function-pixel_render_fill_circle_Bitmap_float2_float_uint: .. das:function:: 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** : :ref:`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 .. _function-pixel_render_fill_circle_Bitmap_int_int_int_uint: .. das:function:: 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** : :ref:`Bitmap ` * **x** : int * **y** : int * **radius** : int * **color** : uint .. _function-pixel_render_fill_circle_Bitmap_int2_int_uint: .. das:function:: 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** : :ref:`Bitmap ` * **center** : int2 * **radius** : int * **color** : uint .. _function-pixel_render_fill_circle_Bitmap_float_float_float_uint: .. das:function:: 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** : :ref:`Bitmap ` * **x** : float * **y** : float * **radius** : float * **color** : uint .. _function-pixel_render_draw_text_Bitmap_int2_string_uint: .. das:function:: 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** : :ref:`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) .. _function-pixel_render_draw_text_Bitmap_int_int_string_uint: .. das:function:: 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** : :ref:`Bitmap ` * **x** : int * **y** : int * **text** : string * **color** : uint .. _function-pixel_render_draw_text_Bitmap_float2_string_uint: .. das:function:: 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** : :ref:`Bitmap ` * **pos** : float2 * **text** : string * **color** : uint .. _function-pixel_render_draw_text_Bitmap_float_float_string_uint: .. das:function:: 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** : :ref:`Bitmap ` * **x** : float * **y** : float * **text** : string * **color** : uint