The MASM Forum

Projects => Game Development => Topic started by: HSE on June 24, 2018, 07:10:53 AM

Title: Have somebody implemented thick line algorithm?
Post by: HSE on June 24, 2018, 07:10:53 AM
Hi!

I'm fighting a little with Murphy's algorithm... but without success  :icon13:.

Perhaps somebody  :icon14:? (whatever thick line algorithm)
Title: Re: Have somebody implemented thick line algorithm?
Post by: avcaballero on June 24, 2018, 06:20:45 PM
Yes, I did it (http://masm32.com/board/index.php?topic=7145.msg78651#msg78651). Bresenham line algorithm
Title: Re: Have somebody implemented thick line algorithm?
Post by: Biterider on June 24, 2018, 07:23:06 PM
Hello HSE
ObjAsm32 has an object called Pixelmap that supports subpixel drawing.   :idea:
The width of a line can be easily achieved by painting adjacent pixels using Besenham, WU, or other similar algos.
I have slightly modified the demo application to draw wider lines (vertical line with 3 px and inner circle with 2 px)
I attach the new exe.  ;)

Biterider
Title: Re: Have somebody implemented thick line algorithm?
Post by: jj2007 on June 24, 2018, 07:28:09 PM
What's wrong with Gdi+ thick lines?
Title: Re: Have somebody implemented thick line algorithm?
Post by: avcaballero on June 24, 2018, 09:29:44 PM
GDI/GDI+ routines are quite slow for making some time critical routines like demos
Title: Re: Have somebody implemented thick line algorithm?
Post by: FORTRANS on June 24, 2018, 09:51:16 PM
Hi,

   When I made a general purpose line drawing routine, it used
a pixel routine to draw pixels on the screen.  By using different
pixel routines, you got different effects.  Black to draw.  White
to erase.  And then patterned pixels for dashed lines and fat
pixels for thick lines.  Certainly wasn't the fastest, but wasn't
really the slowest either.  Except maybe for the fat pixels.

   Faster line routines set the pixel as part of the line drawing
algorithm.  Not as a separate pixel routine.

HTH,

Steve N.
Title: Re: Have somebody implemented thick line algorithm?
Post by: daydreamer on June 24, 2018, 10:19:01 PM
it depends on what you mean: line with just bigger fat size,its just easy to output more pixels in pixel macro/proc and call it from line algo
or nicerlooking search for antialiased bresenham,make code that puts some grey pixels around white line or darker shade of color of the line,especially where the sawshaped line looks worst

Title: Re: Have somebody implemented thick line algorithm?
Post by: HSE on June 25, 2018, 05:37:56 AM
Quote from: caballero on June 24, 2018, 06:20:45 PM
Yes, I did it (http://masm32.com/board/index.php?topic=7145.msg78651#msg78651). Bresenham line algorithm
No. Bresenham algorithm is only for thin lines  :biggrin:

Quote from: Biterider on June 24, 2018, 07:23:06 PM
The width of a line can be easily achieved by painting adjacent pixels using Besenham, WU, or other similar algos.
It's easy if you know line orientation  8)

@FORTRANS && daydreamer :
  It's an expensive solution... but if algorithm don't work   

Quote from: jj2007 on June 24, 2018, 07:28:09 PM
What's wrong with Gdi+ thick lines?
Perhaps GDI+ or other graphics libraries with antialiasing are better, but now I'm trying to draw fast (and simple if posible).

Thanks for the ideas. Now I have a mix. Thin lines are Bresenham drawings. Over that is a normal thick GDI line, witch in theory it's Murphy's algorithm. The idea is to draw that line and to make nicer points in same process. 

Title: Re: Have somebody implemented thick line algorithm?
Post by: HSE on July 03, 2018, 08:22:32 AM
Using Fortrans and Daydreammer "big pixel" line.

Final result not so impressive  :(

Perhaps an antialiased line it's mandatory...
Title: Re: Have somebody implemented thick line algorithm?
Post by: felipe on July 03, 2018, 08:47:00 AM
Nice project and looks difficult too. Congratulations.  :t
Title: Re: Have somebody implemented thick line algorithm?
Post by: HSE on July 06, 2018, 02:06:41 AM
Quote from: felipe on July 03, 2018, 08:47:00 AM
Nice project and looks difficult too.
Yes, nothing easy, and no time for that!

Using GDI+. With the antialiased thick line is far far better I think.
Title: Re: Have somebody implemented thick line algorithm?
Post by: daydreamer on July 06, 2018, 04:16:33 AM
wonder how it looks with dx9 line or poly used as line with fullfledged hardware antialias filter?
Title: Re: Have somebody implemented thick line algorithm?
Post by: HSE on July 06, 2018, 08:20:49 AM
Quote from: daydreamer on July 06, 2018, 04:16:33 AM
wonder how it looks with dx9 line or poly used as line with fullfledged hardware antialias filter?

Fanatics of DirectX assume that everybody know something that I don't know.

I found examples to draw a detailed tiger, planets in movement... but none to draw only a line  :biggrin:

But I was thinking in Biterider solution, I have to see.
Title: Re: Have somebody implemented thick line algorithm?
Post by: Siekmanski on July 06, 2018, 08:22:28 AM
What about stretching a circle to a line?
Title: Re: Have somebody implemented thick line algorithm?
Post by: HSE on July 06, 2018, 10:46:34 AM
Apparently Direct2D is better suited for lines, but again examples are very complex
Title: Re: Have somebody implemented thick line algorithm?
Post by: Siekmanski on July 06, 2018, 08:58:07 PM
Hi HSE,

Just my thoughts,

If you want to calculate a thick line, you could use the bresenham algorithm to draw a line pixel per pixel.
Draw more parallel next to each other to get a thicker line, each color a bit darker to get some antialiasing.

Or, use a texture quad with an antialiased circle or other pattern in it.
Then calculate the angle of the line, rotate the 4 quad coordinates and stretch it along the length of the line.
So that the thickness of the line is equal at any angle of the line.

Or, use the helper libraries from OpenGL, DirectX or the slow GDIplus functions.

The fastest but not the easiest way is, write a pixelshader antialiased line routine.

Here is a pixelshader antialiased line example from Inigo Quilez,
Title: Re: Have somebody implemented thick line algorithm?
Post by: HSE on July 07, 2018, 12:28:36 AM
Thanks Siekmanski!

Without rotation nor antialiasing I have a very nice "Gut" effect  :biggrin:
Title: Re: Have somebody implemented thick line algorithm?
Post by: Siekmanski on July 07, 2018, 03:46:11 AM
:t
Title: Re: Have somebody implemented thick line algorithm?
Post by: HSE on July 07, 2018, 09:47:45 AM
Here is Biterider idea. A lot simpler than what I was thinking.

Drawing a complete line 1000 times take:

    GDI+    10500ms
    GDI        1550ms 
    bigpixel   1010ms
    pipeline    500ms

Of course they are different things, but comparisons are interesting.
Title: Re: Have somebody implemented thick line algorithm?
Post by: HSE on July 08, 2018, 05:52:59 AM
After some hours (trying to remember trigonometry :biggrin:)

Better now but 1000 complete lines take 1420ms 810ms (Sorry, I forget part of color calculation inside loops).  It's similar to big pixel  (now only points corresponding to parallel lines like Biterider idea) that is taking 478ms.

I think that because of dark margin antialiasing is unnecesary with a black background.

Thanks. Regards
Title: Re: Have somebody implemented thick line algorithm?
Post by: daydreamer on August 19, 2018, 12:21:08 AM
Quote from: HSE on July 06, 2018, 08:20:49 AM
Quote from: daydreamer on July 06, 2018, 04:16:33 AM
wonder how it looks with dx9 line or poly used as line with fullfledged hardware antialias filter?

Fanatics of DirectX assume that everybody know something that I don't know.

I found examples to draw a detailed tiger, planets in movement... but none to draw only a line  :biggrin:
I didnt tell you because I am a dx fanatic,I told you because I want to help you and other members getting all alternatives to choose from otherwise you dont get the whole Picture
dx9 drawprimitive you see mostly TRIANGLELIST,TRIANGLESTRIP, less known is TRIANGLEFAN
found this interesting link
http://zophusx.byethost11.com/tutorial.php?lan=dx9&num=10&i=1 (http://zophusx.byethost11.com/tutorial.php?lan=dx9&num=10&i=1)

actually wanted to ask question on whats smallest line algo?fpu or cpu drawing to a backbuffer I mean?
one initial fdiv smallest/biggest distance and fadd that and fadd 1 for each pixel in a loop?
same with fixed Point and cpu?but that maybe requires additional code with many bitshifting?

Title: Re: Have somebody implemented thick line algorithm?
Post by: HSE on August 19, 2018, 02:37:01 AM
Quote from: daydreamer on August 19, 2018, 12:21:08 AM
I didnt tell you because I am a dx fanatic
Don't worry, the writer of that article also is a fanatic.  :biggrin:

Apparently the "line" is only one code line.

If You know were to put that line, fantastic  :t

Nowhere there is a working full program source code to draw a simple line. There is tutorials  with everything you need to draw a planetary system in movement or things so complex like that.

It's very interesting and perhaps some day I will study those tutorials. But now I'm not going to read 11 tutorials to draw a line  :biggrin:

Quote from: daydreamer on August 19, 2018, 12:21:08 AM
actually wanted to ask question on whats...

My english is a little limited (is what in this forum is know as pseudo-english). I really don't understand what you ask. Try to make complete questions,  different question in different lines, and capital letters sometimes are usefull  :t