{"id":15722586,"url":"https://github.com/agulev/drawpixels","last_synced_at":"2026-03-03T18:01:33.205Z","repository":{"id":83444276,"uuid":"129390982","full_name":"AGulev/drawpixels","owner":"AGulev","description":"Defold engine native extension for drawing pixels into texture buffer.","archived":false,"fork":false,"pushed_at":"2026-01-15T19:34:53.000Z","size":138,"stargazers_count":92,"open_issues_count":6,"forks_count":13,"subscribers_count":6,"default_branch":"master","last_synced_at":"2026-01-15T21:51:38.492Z","etag":null,"topics":["defold","defold-game-engine","defold-library","defold-module","draw"],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AGulev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2018-04-13T11:09:21.000Z","updated_at":"2026-01-15T19:35:02.000Z","dependencies_parsed_at":"2024-10-24T16:50:57.071Z","dependency_job_id":"8ee9f514-2a55-465c-8052-a1b02e946e47","html_url":"https://github.com/AGulev/drawpixels","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/AGulev/drawpixels","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AGulev%2Fdrawpixels","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AGulev%2Fdrawpixels/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AGulev%2Fdrawpixels/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AGulev%2Fdrawpixels/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AGulev","download_url":"https://codeload.github.com/AGulev/drawpixels/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AGulev%2Fdrawpixels/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30053986,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-03T17:46:22.538Z","status":"ssl_error","status_checked_at":"2026-03-03T17:46:22.036Z","response_time":61,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["defold","defold-game-engine","defold-library","defold-module","draw"],"created_at":"2024-10-03T22:08:35.018Z","updated_at":"2026-03-03T18:01:33.184Z","avatar_url":"https://github.com/AGulev.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Draw Pixels\n\n[![Build Status](https://github.com/AGulev/drawpixels/workflows/Build%20with%20bob/badge.svg)](https://github.com/AGulev/drawpixels/actions)\n\n![15f0e5a685b5c7f16ef78f612c377e4cab08ce8a](https://github.com/user-attachments/assets/4c9d1ead-74e2-4675-ab51-a9ddf63c15da)\n\n[Defold engine](http://www.defold.com) native extension for drawing pixels and simple geometry into texture buffer.\n\nFeel free to contribute!\n\n\u003ePlease, pay attension!\nThe size of the image you manipulate with DrawPixels must match that of the atlas, not the sprite image. Otherwise you need to know where the sprite is the atlas and update that region of the atlas.\n\n## Installation\nTo use this library in your Defold project, add the needed version URL to your `game.project` dependencies from [Releases](https://github.com/AGulev/drawpixels/releases)\n\n\u003cimg width=\"401\" alt=\"image\" src=\"https://user-images.githubusercontent.com/2209596/202223571-c77f0304-5202-4314-869d-7a90bbeec5ec.png\"\u003e\n\n\n## Example\n![screenshot](https://user-images.githubusercontent.com/2209596/45321616-7f24e100-b54e-11e8-9821-00b1b2e36a97.jpg)\n\nMain code example is [here](https://github.com/AGulev/drawpixels/blob/master/example/canvas.script)\n\n## Lua API\nFirst of all you need to create a table with a buffer information that contain next fields:\n\n`buffer` - buffer\u003cbr /\u003e\n`width` - buffer width, same as your texture width\u003cbr /\u003e\n`height` - buffer height, same as your texture height\u003cbr /\u003e\n`channels` - 3 for rgb, 4 for rgba\u003cbr /\u003e\n`premultiply_alpha` - alpha value will be premultiplied into the RGB color values. Optional parameter. Default is false.\u003cbr /\u003e\n\nFor example:\n```lua\nlocal buffer_info = {\n    buffer = buffer.create(1024 * 2048, -- size of the buffer width*height\n    {{\n      name = hash(\"my_buffer\"),\n      type = buffer.VALUE_TYPE_UINT8,\n      count = 4 -- same as channels\n    }}),\n    width = 1024,\n    height = 2048,\n    channels = 4,\n    premultiply_alpha = true\n  }\n```\nThen when you have a buffer info, you can use next methods:\n\n#### drawpixels.circle(buffer_info, pox_x, pox_y, diameter, red, green, blue, alpha, antialiasing, width)\nMethod for drawing circle:\n\n`buffer_info` - buffer information\u003cbr /\u003e\n`pox_x` - x position center of the circle\u003cbr /\u003e\n`pox_y` - y position center of the circle\u003cbr /\u003e\n`diameter` - diameter of the circle\u003cbr /\u003e\n`red` - red channel of the color 0..255\u003cbr /\u003e\n`green` - green channel of the color 0..255\u003cbr /\u003e\n`blue` - blue channel of the color 0..255\u003cbr /\u003e\n`alpha` - alpha channel 0..255. Optional parameter for rgba textures\u003cbr /\u003e\n`antialiasing` - adds anti-aliasing. Only for 4 channels. Optional parameter.\u003cbr /\u003e\n`width` - indicates the circle width. Only for circle with anti-aliasing. Optional parameter.\u003cbr /\u003e\n\n#### drawpixels.filled_circle(buffer_info, pos_x, pos_y, diameter, red, green, blue, alpha, antialiasing)\nMethod for drawing filled circle:\n\n`buffer_info` - buffer information\u003cbr /\u003e\n`pox_x` - x position center of the circle\u003cbr /\u003e\n`pox_y` - y position center of the circle\u003cbr /\u003e\n`diameter` - diameter of the circle\u003cbr /\u003e\n`red` - red channel of the color 0..255\u003cbr /\u003e\n`green` - green channel of the color 0..255\u003cbr /\u003e\n`blue` - blue channel of the color 0..255\u003cbr /\u003e\n`alpha` - alpha channel 0..255. Optional parameter for rgba textures\u003cbr /\u003e\n`antialiasing` - adds anti-aliasing. Only for 4 channels. Optional parameter.\u003cbr /\u003e\n\n#### drawpixels.rect(buffer_info, pos_x, pos_y, rect_width, rect_height, red, green, blue, alpha)\nMethod for drawing rectangle:\n\n`buffer_info` - buffer information\u003cbr /\u003e\n`pox_x` - x position center of the rectangle\u003cbr /\u003e\n`pox_y` - y position center of the rectangle\u003cbr /\u003e\n`rect_width` - rectangle width\u003cbr /\u003e\n`rect_height` - rectangle height\u003cbr /\u003e\n`red` - red channel of the color 0..255\u003cbr /\u003e\n`green` - green channel of the color 0..255\u003cbr /\u003e\n`blue` - blue channel of the color 0..255\u003cbr /\u003e\n`alpha` - alpha channel 0..255. Optional parameter for rgba textures\u003cbr /\u003e\n\n#### drawpixels.filled_rect(buffer_info, pos_x, pos_y, rect_width, rect_height, red, green, blue, alpha, angle)\nMethod for drawing filled rectangle:\n\n`buffer_info` - buffer information\u003cbr /\u003e\n`pox_x` - x position center of the rectangle\u003cbr /\u003e\n`pox_y` - y position center of the rectangle\u003cbr /\u003e\n`rect_width` - rectangle width\u003cbr /\u003e\n`rect_height` - rectangle height\u003cbr /\u003e\n`red` - red channel of the color 0..255\u003cbr /\u003e\n`green` - green channel of the color 0..255\u003cbr /\u003e\n`blue` - blue channel of the color 0..255\u003cbr /\u003e\n`alpha` - alpha channel 0..255. Optional parameter for rgba textures\u003cbr /\u003e\n`angle` - rotation angle in degrees. Optional.\u003cbr /\u003e\n\n#### drawpixels.fill(buffer_info, red, green, blue, alpha)\nFill buffer with the color:\n\n`buffer_info` - buffer information\u003cbr /\u003e\n`red` - red channel of the color 0..255\u003cbr /\u003e\n`green` - green channel of the color 0..255\u003cbr /\u003e\n`blue` - blue channel of the color 0..255\u003cbr /\u003e\n`alpha` - alpha channel 0..255. Optional parameter for rgba textures\u003cbr /\u003e\n\n#### drawpixels.line(buffer_info, x0, y0, x1, y1, red, green, blue, alpha, antialiasing, width)\nDraw a line between two points:\n\n`buffer_info` - buffer information\u003cbr /\u003e\n`x0` - x position of one end of the line\u003cbr /\u003e\n`y0` - y position of one end of the line\u003cbr /\u003e\n`x1` - x position of the other end of the line\u003cbr /\u003e\n`y1` - y position of the other end of the line\u003cbr /\u003e\n`red` - red channel of the color 0..255\u003cbr /\u003e\n`green` - green channel of the color 0..255\u003cbr /\u003e\n`blue` - blue channel of the color 0..255\u003cbr /\u003e\n`alpha` - alpha channel 0..255. Optional parameter for rgba textures\u003cbr /\u003e\n`antialiasing` - adds anti-aliasing. Only for 4 channels. Optional parameter.\u003cbr /\u003e\n`width` - indicates the line width. Only for line with anti-aliasing. Optional parameter.\u003cbr /\u003e\n\n#### drawpixels.gradient_line(buffer_info, x0, y0, x1, y1, red1, green1, blue1, red2, green2, blue2, alpha, antialiasing, width)\nDraw a gradient line between two points:\n\n`buffer_info` - buffer information\u003cbr /\u003e\n`x0` - x position of one end of the line\u003cbr /\u003e\n`y0` - y position of one end of the line\u003cbr /\u003e\n`x1` - x position of the other end of the line\u003cbr /\u003e\n`y1` - y position of the other end of the line\u003cbr /\u003e\n`red1` - first red channel of the color 0..255\u003cbr /\u003e\n`green1` - first green channel of the color 0..255\u003cbr /\u003e\n`blue1` - first blue channel of the color 0..255\u003cbr /\u003e\n`red2` - second red channel of the color 0..255\u003cbr /\u003e\n`green2` - second green channel of the color 0..255\u003cbr /\u003e\n`blue2` - second blue channel of the color 0..255\u003cbr /\u003e\n`alpha` - alpha channel 0..255\u003cbr /\u003e\n`antialiasing` - adds anti-aliasing. Only for 4 channels. Optional parameter.\u003cbr /\u003e\n`width` - indicates the line width. Only for line with anti-aliasing. Optional parameter.\u003cbr /\u003e\n\n#### drawpixels.arc(buffer_info, x, y, radius, from, to, red, green, blue, alpha)\nDraw a arc between two corners. If from \u003c to the arc is drawn counterclockwise. If from \u003e to the arc is drawn clockwise. Only for 4 channels:\n\n`buffer_info` - buffer information\u003cbr /\u003e\n`x` - x position center of the circle\u003cbr /\u003e\n`y` - y position center of the circle\u003cbr /\u003e\n`radius` - radius of the circle\u003cbr /\u003e\n`from` - first arc angle in radians. May be negative\u003cbr /\u003e\n`to` - second arc angle in radians. May be negative\u003cbr /\u003e\n`red` - red channel of the color 0..255\u003cbr /\u003e\n`green` - green channel of the color 0..255\u003cbr /\u003e\n`blue` - blue channel of the color 0..255\u003cbr /\u003e\n`alpha` - alpha channel 0..255\u003cbr /\u003e\n\n#### drawpixels.filled_arc(buffer_info, x, y, radius, from, to, red, green, blue, alpha)\nDraw a filled arc between two corners. If from \u003c to the arc is drawn counterclockwise. If from \u003e to the arc is drawn clockwise. Only for 4 channels:\n\n`buffer_info` - buffer information\u003cbr /\u003e\n`x` - x position center of the circle\u003cbr /\u003e\n`y` - y position center of the circle\u003cbr /\u003e\n`radius` - radius of the circle\u003cbr /\u003e\n`from` - first arc angle in radians. May be negative\u003cbr /\u003e\n`to` - second arc angle in radians. May be negative\u003cbr /\u003e\n`red` - red channel of the color 0..255\u003cbr /\u003e\n`green` - green channel of the color 0..255\u003cbr /\u003e\n`blue` - blue channel of the color 0..255\u003cbr /\u003e\n`alpha` - alpha channel 0..255\u003cbr /\u003e\n\n#### drawpixels.gradient_arc(buffer_info, x, y, radius, from, to, red1, green1, blue1, red2, green2, blue2, alpha)\nDraw a gradient arc between two corners. If from \u003c to the arc is drawn counterclockwise. If from \u003e to the arc is drawn clockwise. Only for 4 channels:\n\n`buffer_info` - buffer information\u003cbr /\u003e\n`x` - x position center of the circle\u003cbr /\u003e\n`y` - y position center of the circle\u003cbr /\u003e\n`radius` - radius of the circle\u003cbr /\u003e\n`from` - first arc angle in radians. May be negative\u003cbr /\u003e\n`to` - second arc angle in radians. May be negative\u003cbr /\u003e\n`red1` - first red channel of the color 0..255\u003cbr /\u003e\n`green1` - first green channel of the color 0..255\u003cbr /\u003e\n`blue1` - first blue channel of the color 0..255\u003cbr /\u003e\n`red2` - second red channel of the color 0..255\u003cbr /\u003e\n`green2` - second green channel of the color 0..255\u003cbr /\u003e\n`blue2` - second blue channel of the color 0..255\u003cbr /\u003e\n`alpha` - alpha channel 0..255\u003cbr /\u003e\n\n#### drawpixels.pixel(buffer_info, x, y, red, green, blue, alpha)\nDraw a pixel:\n\n`buffer_info` - buffer information\u003cbr /\u003e\n`x` - x position of pixel\u003cbr /\u003e\n`y` - y position of pixel\u003cbr /\u003e\n`red` - red channel of the color 0..255\u003cbr /\u003e\n`green` - green channel of the color 0..255\u003cbr /\u003e\n`blue` - blue channel of the color 0..255\u003cbr /\u003e\n`alpha` - alpha channel 0..255. Optional parameter for rgba textures\u003cbr /\u003e\n\n#### drawpixels.color(buffer_info, x, y)\nRead color from a position in the buffer:\n\n`buffer_info` - buffer information\u003cbr /\u003e\n`x` - x position to get color from\u003cbr /\u003e\n`y` - y position to get color from\u003cbr /\u003e\n\nRETURNS:\n\n`red` - red channel of the color 0..255\u003cbr /\u003e\n`green` - green channel of the color 0..255\u003cbr /\u003e\n`blue` - blue channel of the color 0..255\u003cbr /\u003e\n`alpha` - alpha channel 0..255. Optional parameter for rgba textures\u003cbr /\u003e\n\n#### drawpixels.bezier(buffer_info, x0, y0, xc, yc, x1, y1, red, green, blue, alpha)\nDraw a bezier line between two points and one control point:\n\n`buffer_info` - buffer information\u003cbr /\u003e\n`x0` - x position of the first point\u003cbr /\u003e\n`y0` - y position of the first point\u003cbr /\u003e\n`xc` - x position of the control point\u003cbr /\u003e\n`yc` - y position of the control point\u003cbr /\u003e\n`x1` - x position of the second point\u003cbr /\u003e\n`y1` - y position of the second point\u003cbr /\u003e\n`red` - red channel of the color 0..255\u003cbr /\u003e\n`green` - green channel of the color 0..255\u003cbr /\u003e\n`blue` - blue channel of the color 0..255\u003cbr /\u003e\n`alpha` - alpha channel 0..255. Optional parameter for rgba textures\u003cbr /\u003e\n\nYou can fill in a specific area. To do this, you need to identify the borders with `start_fill` method and call the `fill_area` method to fill the area. Borders work with: lines, gradient lines, circles, filled circles with anti-aliasing, pixels, arcs. \u003cb\u003eNOT WORK WITH FILLED ARCS AND GRADIENT ARCS.\u003c/b\u003e The arcs themselves use this method, so the fill may not be predictable. Do not create arcs until you are done with the fill. Be sure to call the `end_fill` method when you stop working with the fill.\n\n#### drawpixels.start_fill()\nIndicates the start of border preservation.\n\n#### drawpixels.end_fill()\nIndicates the stop of border preservation.\n\n#### drawpixels.fill_area(buffer_info, x, y, red, green, blue, alpha)\nFills an area at specified boundaries. Only for 4 channels:\n\n`buffer_info` - buffer information\u003cbr /\u003e\n`x` - x position of the start point\u003cbr /\u003e\n`y` - y position of the start point\u003cbr /\u003e\n`red` - red channel of the color 0..255\u003cbr /\u003e\n`green` - green channel of the color 0..255\u003cbr /\u003e\n`blue` - blue channel of the color 0..255\u003cbr /\u003e\n`alpha` - alpha channel 0..255\u003cbr /\u003e\n\nIn order to draw this into a sprite, you need a separate atlas with power of two texture. Then we can use `resource.set_texture`:\n\n```lua\nresource.set_texture(go.get(\"#sprite\", \"texture0\"), self.header, self.buffer_info.buffer)\n```\n\nIn order to render this in gui, we just need to create a box and create a new texture.\nWe can use `gui.new_texture`. Then you need to set this texture to the box using `gui.set_texture`:\n\n```lua\nlocal data = buffer.get_bytes(self.buffer_info.buffer, hash(\"rgba\"))\ngui.new_texture(\"name\", width, height, image.TYPE_RGBA, data)\ngui.set_texture(gui.get_node(\"box\"), \"name\")\ngui.set_size(gui.get_node(\"box\"), vmath.vector3(width, height, 0))\n```\n\n--------\n\nIf you have any questions or suggestions contact me: me@agulev.com\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fagulev%2Fdrawpixels","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fagulev%2Fdrawpixels","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fagulev%2Fdrawpixels/lists"}