• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!
  • Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Question - Code drawing lines not recommended?

Z

zendorf

Guest
In the GMS2 new functions article on the yoyo site, it recommends not to use line drawing functions anymore in GMS2. I would like some more info on this as the manual makes no mention of it. Does this also apply to draw_circle and draw_rectangle?

I have tried my game ,which uses some draw_line and draw_line_width functions, and had no issues on about 5 different machines all with various GPU's (Intel and Nvidia).

Are there any specific GPU's that are problematic? Since I have no AMD cards, are they more likely to have an issue?

cheers....
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Afaik, it's only draw-line functions... and it's easy enough to work around by using a 1px sprite and simply stretching it using draw_sprite_ext. The manual will be updated to explain this (possible) issue for the related functions.
 
Z

zendorf

Guest
Afaik, it's only draw-line functions... and it's easy enough to work around by using a 1px sprite and simply stretching it using draw_sprite_ext. The manual will be updated to explain this (possible) issue for the related functions.
Thanks for the reply. I am mostly using draw_line width to make trails with variable widths.

I guess I could also use draw_rectangle for these as well as what you suggested. Not sure of the math to stretch a sprite to get it to draw from an arbitrary x1,y1 to x2,y2 (of course it would be easy at 90 degree increments). For the time being the draw_line_width is working fine.

Would be interested to hear from anyone who has found the line drawing to be flaky on their pc...
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
From the release notes:

"Line drawing - unfortunately line drawing is not consistently implemented by hardware vendors, this means that between different manufacturers and different drivers from the same manufacturer you may get different results, we reccomend that you do not rely on line drawing in released games, but the functions are still there for you to try."

I can say no more than that, sorry. I'll tag @Mike and @rwkay to see if they can expand on the reply... :)
 
Z

zendorf

Guest
ok, thanks. As long as it works on the majority of GPU's I am happy to use it. Though I would be nervous if it was part of one of my main game mechanics...
 

Mike

nobody important
GMC Elder
Yeah.... while all graphics drivers do line drawing, the location, offset, shifting around of start and end points varies a lot, and it's not something we can compensate for. So while line drawing is there and won't be going anywhere, if you're depending on it to draw exactly from point A to point B, that may not happen on all graphics cards and drivers. Because of this, we keep getting bugs being filed saying it's wrong. It is... but there's nothing we can do about it. We've basically picked one machine in the office and will make it work on that machine. Outside of that.... complain to the graphics guys. :(

The same is also true of points BTW... Although they do seem more consistent, you can still get the issue of points being miss-aligned. I use points a lot, so I have to adapt code for different platforms and drivers - which is really annoying, but not something that's fixable. To make things fully compatible, then drawing a sprite with a pixel on it seems to be the best way - albeit MUCH slower.

When you get right down to it, graphics cards now focus on textured triangle rendering and shaders. The rest of it is there... but they don't really care. Many cards render lines and points using very thin or small triangles as it is.

This all becomes less of an issue if your doing 3D as there's no real "exact" location as you would get in 2D so you get away with it more, and that's really were lines are used in GFX hardware these days - wire frame type views.
 
Z

zendorf

Guest
@Mike thanks for the explanation. Presumably this is a result of using DX11, or was DX9/1.4 also problematic with line drawing?

Are any of the other drawing functions potentially problematic such as draw_line_width, draw rectangle and draw_circle? What is the expected result with one of these suspect drivers...will it still draw a line, but be off by several pixels or not likely to draw the line at all?

cheers!
 

Mike

nobody important
GMC Elder
It's across the board. As the years have gone on, it's just gotten worse is all....

anything with lines will have issues, and those issues will vary from totally fine, to just "off" a bit in random directions. Should (probably) always draw "something" though - unless its a very small line, then who knows.

Filled stuff uses polys so should be fine.
 
M

McWolke

Guest
Afaik, it's only draw-line functions... and it's easy enough to work around by using a 1px sprite and simply stretching it using draw_sprite_ext. The manual will be updated to explain this (possible) issue for the related functions.
if using a 1px sprite works perfectly fine but drawing a line doesn't, why isn't draw_line implemented internally with the sprite workaround? just curious
 
Z

zendorf

Guest
Because that would be so slow, I could send over my granny to plot the same dots on screen using her bingo marker and have her back here before it would be finished.
Couldn't the native draw_line_width be rewritten by Yoyo to use 2 triangle polys for each line? I am going to have a go at writing a script that will use the draw_primitive and triangle list to do this, but I fear it will be a lot slower than if it was done natively in the engine.
 
I feel the pain with this one as my artillery game uses draw_line for the destructible terrain and since a GFX driver update it hasn't worked correctly on my laptop. Leaves completely invisible lines, etc... yay
 

Mike

nobody important
GMC Elder
draw_line_width does use 2 triangles (as hardware lines do not scale), so you could use this and it will work - it's probably not as quick but....

and yes, it's BOTH gfx hardware and drivers to blame.,
 

Juju

Member
Couldn't the native draw_line_width be rewritten by Yoyo to use 2 triangle polys for each line?
Yes.

Edit:
Oh Mike beat me to it, the scoundrel. For a fun project, try adding rounded caps to the end of the line in the most efficient way possible (don't just use circles!).

Code:
///draw_line_width_poly( x1, y1, x2, y2, width )
//
// 2017/01/29
// @jujuadams

var _x1 = argument0;
var _y1 = argument1;
var _x2 = argument2;
var _y2 = argument3;
var _w  = argument4;

var _d  = _w * 0.5 / point_distance( _x1, _y1, _x2, _y2 );
var _dx = ( _x2 - _x1 ) * _d;
var _dy = ( _y2 - _y1 ) * _d;

draw_primitive_begin( pr_trianglestrip );
draw_vertex( _x1 + _dy, _y1 - _dx );
draw_vertex( _x2 + _dy, _y2 - _dx );
draw_vertex( _x1 - _dy, _y1 + _dx );
draw_vertex( _x2 - _dy, _y2 + _dx );
draw_primitive_end();
 
Z

zendorf

Guest
draw_line_width does use 2 triangles (as hardware lines do not scale), so you could use this and it will work - it's probably not as quick but....

and yes, it's BOTH gfx hardware and drivers to blame.,
Aha, now that I know that, I will just use that function and not the plain draw_line. Cheers!

@Juju thanks for whipping that up, it could also be useful :)
 

DeScruff

Member
Huh that explains everything. Ive noticed draw_line issues in GMS1 where it wouldn't draw on the starting pixel, and so I just decided not to use it.
 
Yes.

Edit:
Oh Mike beat me to it, the scoundrel. For a fun project, try adding rounded caps to the end of the line in the most efficient way possible (don't just use circles!).

Code:
///draw_line_width_poly( x1, y1, x2, y2, width )
//
// 2017/01/29
// @jujuadams

var _x1 = argument0;
var _y1 = argument1;
var _x2 = argument2;
var _y2 = argument3;
var _w  = argument4;

var _d  = _w * 0.5 / point_distance( _x1, _y1, _x2, _y2 );
var _dx = ( _x2 - _x1 ) * _d;
var _dy = ( _y2 - _y1 ) * _d;

draw_primitive_begin( pr_trianglestrip );
draw_vertex( _x1 + _dy, _y1 - _dx );
draw_vertex( _x2 + _dy, _y2 - _dx );
draw_vertex( _x1 - _dy, _y1 + _dx );
draw_vertex( _x2 - _dy, _y2 + _dx );
draw_primitive_end();
I used this for the terrain_redraw script instead of draw_line_width, like the look better, working good again. Thanks for the post.
 

chance

predictably random
Forum Staff
Moderator
Despite the quirks, I hope there's no plans to remove the draw_line(), draw_circle(), draw_rectangle(). functions. Because they are VERY useful for short-lived visual effects like trails, explosions, etc. They're also great for temporary diagnostics.

They aren't always reliable for drawing persistent features, but in many applications these minor quirks aren't detectable. So these functions still have plenty of use in game making.
 

Mike

nobody important
GMC Elder
If things are moving (like 2D or 3D vectorss etc) then you'll never notice the quirks. It's really if you're doing "static" lines from A to B, you notice that it "may" be off by a pixel in places.
So they aren't terrible for lots of things, but they also aren't suitable for many others. So use with caution... but use where you think they make sense.
 
Top