Thanks for the tip. It works.
However, there is a problem. The entire viewport works as $testButton.normal = tex when I run the following code. In other words, the icon.png gets rendered, when I click anywhere in the output screen.
How do I make the small viewport that you have suggested? When I make a small viewport node as a child of the root viewport, it does not allow drawing of the polygon in the draw function. It does not recognise drawpolygon(points,colour) function in extends Viewport script.
extends Control
func _ready():
var img = get_viewport().get_texture().get_data()
# Flip on the Y axis.
# You can also set "V Flip" to true if not on the root Viewport.
# img.flip_y()
# Convert Image to ImageTexture.
var tex = ImageTexture.new()
tex.create_from_image(img)
$testButton.normal = tex
$testButton.pressed = load("res://icon.png")
# yield(VisualServer, "frame_post_draw")
func _draw():
var points = PoolVector2Array()
var colour = PoolColorArray()
points = [Vector2(100,100), Vector2(200,100), Vector2(200,200),Vector2(100,200)]
colour = [Color(0,0,1,1)]
draw_polygon(points,colour)
Thanks in advance.