• Godot HelpProgramming
  • i made a drawing program. ¿how could i draw the last-drawn line into the image texture?

i have made a simple Line Drawing prototype that is practically a clone of 2D GD Paint Demo.

the part that i need but cannot do should happen in the Pencil script, every time i release my finger/mouse: drawing the 500×500px area that is within the "Canvas" area onto the "ImageTexture" Sprite node. i could already make the part that should happen afterwards: clearing the points Array because at this point the Line should have been drawn into ImageTexture.

before you ask why i need to draw the line into the texture: re-drawing all the points every time a new point is added quickly becomes inefficient, especially on phones where it goes to less than 10 fps. in less than 30 seconds of drawing time. if i could instead draw the last-drawn line into a texture after it's been finished drawing, i could clear the points array so that i can draw the next line with close-to-maximum performance again.

please take a look in my project (especially the "Pencil" script) and explain me how i could draw the line into the "image texture" Sprite node, because i have node idea where to start.

even though i still don't understand how this works, thanks for the direction. i will need either doing more research or an easier and more precise explaination.

Basically you add a viewport node, and place your drawing area as a child of that node. Then you use your reference viewport node to call the function "get_texture().get_data()", which returns an Image. Then you have the drawing and you can do with the Image want you want.

thanks very much to you and to Godot Tutorials (yes, that's his YouTube and GitHub username) for this simple explaination of how the "Viewport" Node works. my result is This.

of course, it's still a prototype and not supposed to be the final program. if this Was supposed to be the final program, saving the current line as a texture would've been an absurd way of keeping the line on-screen until drawing the next line (then i could've just not cleared the "points" array until drawing the next line).

in the final program, i will have it so that the new line always gets added on top of the current texture with the other drawn lines instead of overriding it. but if i have problems with that, i will ask a new question so that things don't get too messy here on the forums.

Update

it's only when i tested on my computer that the previous line still gets deleted before the next one is drawn.

when testing on my phone (which is the target platform of my drawing program), this Does work as intended: drawing the new line on top of all the old ones.

and just as i planned, the program regains Top Performance every time i finish drawing a line.

???

a year later