Code draws are broken by 2D stretching.
Operating system or device - Godot version:
Fedora 24 - 64 Bits. Godot 2.1
Issue description (what happened, and what was expected):
What happened: The draw was broken. What was expected: The draw was not broken.
Steps to reproduce: gradient.tar.gz
- Set, Project Settings > Display > strech_mode : ON, 2d.
- Set, Project Settings > Display > strech_aspect : ON, keep.
- Draw something by code.
- Resize the windows.
Link to minimal example project (optional but very welcome):
https://drive.google.com/drive/folders/0B1QcObgYNJ_PMVY3YlBhbThwQkk gradient.tar.gz
(sorry my english) Problem persists in build March 16, 2017 at 16:49 from UNOFFICIAL GODOT ENGINE BUILD (3.0 alpha) http://fixnum.org/godot/

In 2.1.2 work well

@Rocket-Buddha, in 2D stretch mode you have a virtual resolution, which is, the size of the viewport matching more or less accurately your display_width/height depending on the stretch_aspect setting. For keep that is matched exactly.
And you have a physical resolution, namely the size of the window, as returned by OS.get_window_size().
So if you want to draw at exact physical pixel locations you have to apply the proportion. Moreover, in your example you want to draw one line per physical row of pixels and to do that you have to issue one line draw call for every one so as not to leave gaps.
Try with this code:
extends Node2D
var from
var to
var start_color
var end_color
var widt
var screen_size
func _ready():
from = Vector2(0,0)
#start_color = Color("2E286E")
#end_color = Color("51379B")
start_color = Color("FF0000")
end_color = Color("0000FF")
widt = 1
get_node("AnimationPlayer").play("basic")
set_process(true)
func _process(delta):
update()
func _draw():
screen_size = OS.get_window_size()
to = Vector2(screen_size.x,0)
var dif_red =(end_color.r8 - start_color.r8)/screen_size.y
var dif_green=(end_color.g8 - start_color.g8)/screen_size.y
var dif_blue =(end_color.b8 - start_color.b8)/screen_size.y
var current_color = start_color
for i in range(screen_size.y+1):
current_color.r8 = round(start_color.r8 + (i * dif_red))
current_color.g8 = round(start_color.g8 + (i * dif_green))
current_color.b8 = round(start_color.b8 + (i * dif_blue))
from.y = i * get_viewport_rect().size.y / screen_size.y
to.y = from.y
draw_line(from,to,current_color,widt)
This one redraws the scene on every frame to be able to adapt to window size changes. The proportion is computed on every line instead of being precomputed since that way you can avoid more precission errors. In the end, this kind of drawing code will be affected by them depending on the physical resolution.
A better approach would be to render thin rects instead. That way in the case rounding errors would leave a one-pixel-thick gap, the relevant line/rect would be two-pixels-thick. But there's not too much more you can do if working at this level.
@Shockblast, are you still experiencing your issue on 3.0?
@RandomShaper nop, the problem is already fixed in #8426
@akien-mga, the OP issue is expected behavior as far as I can tell and the other issue reported here is reported as already fixed.
Time to close?