#What is the fastest way to draw pixels on a 2D screen or canvas

9 messages · Page 1 of 1 (latest)

flint gyro
#

I need a way to just change the color of pixels in my godot screen, preferably a low level / efficient way (so no tilemaps etc)
i do plan on using gdscript, so no c# or c++.
ill also use a low resolution and then scale it up so the pixels will be more visible.

vocal agate
#

Things that can draw arbitrary things on screen:

  • Sprite2D, AnimatedSprite2D
  • GPUParticles2D
  • Line2D
  • MeshInstance2D, MultimeshInstance2D
  • Polygon2D
  • TileMap
  • ColorRect
  • TextureRect

And finally

  • Any Node2D's func _draw() being overriden to use the various draw_x functions (draw_point, draw_line, draw_circle, etc)
warped rain
#

depending on what your specific goal is, maybe you can use post processing and LUTS

flint gyro
#

wanna make a particle sim or just some automata game

#

so ill guess ill use a Node2D with a _draw function

vocal agate
#

you can either use draw_primitive to draw pixels directly by providing a single point

or you can create an image texture and use set_pixel() to set dots on it, then draw that texture with draw_texture(), or apply it to a sprite/texture rect. that might be more efficient

flint gyro
#
extends Node2D

const IMAGEFORMAT = Image.FORMAT_RGBA8
var image : Image
var texture : ImageTexture

@onready var SIZE : Vector2 = DisplayServer.window_get_size()

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
    image = Image.create(SIZE.x, SIZE.y, false, IMAGEFORMAT)
    texture = ImageTexture.new()
    texture.set_image(image)

func _process(delta: float) -> void:
    queue_redraw()

func _draw() -> void:
    image.set_pixel(0,0, Color.RED)
#

what am i doing wrong here, no pixel seems to draw

#

should i also add an texturerect node and assign the texture to it?