Results 1 to 16 of 16

Thread: antialiased line...

  1. #1

    Thread Starter
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755

    Talking antialiased line...

    in every thread there someone giving an url to a C way of draing antialiased lines but i wanna know a VB way....
    im making a paint prog and i cant stand the ugly lines in the picturebox!

    Please help me!

  2. #2
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    At 2x - 10x resolution, draw your line (at 2 width to 10 width respectively). Then scale it down to 1x, your 1:1 zoom level. Doing this with StretchBlt or PaintPicture wont produce good results. Rather, do this with an anti-aliased stretch function, I'm sure you can find the source for this. There also may be just a plain old aa'd line function somewhere, if you find one let me know.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  3. #3
    Frenzied Member
    Join Date
    Jun 2000
    Location
    England, Buckingham
    Posts
    1,341
    proper alised lines work by a process of getting the color value of the pixel and the four around it (above, below, left and right) then taking an average (i think this is it). so if u can use GetPixel and SetPixel ?

  4. #4
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    You mean anti-aliased don't ya psy? Anyways they actually work the way I showed, and that's the best course of action to take, I believe...
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  5. #5
    Frenzied Member /\/\isanThr0p's Avatar
    Join Date
    Jul 2000
    Location
    They can't stop us! We're on a misson from God.
    Posts
    1,181
    for just a line I believe in Psy's method
    for a full rendered picture, it has to be rendered in a higher res and than downscaled.
    Sanity is a full time job

    Puh das war harter Stoff!

  6. #6

    Thread Starter
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755

    Question colors...

    how do i get the average color then? do i have to get the rgv value or do i use bitblt to mix them?
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  7. #7

    Thread Starter
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755

    ooops

    rgv=rgb
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  8. #8
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    rgb is a 3dvector, get the mean by for each component sum terms and divide by two. To alphablend multiply by factor a for each component in left term, 1-a for right term
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  9. #9

    Thread Starter
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755

    thanks

    ok...ill try that when i get home...
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  10. #10

    Thread Starter
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755

    damn!

    it didnt work out fine...

    if i have drawwidth = 1 it looked pretty ok but if i set it to a higher value i could see the dots (lines) better and it looked like ****!

    i think it would look better if i used setpixel instead...but if i move the mouse fast when i draw i just get dots

    is there anyway to get lines with setpixel instead? even if it would slow it down?

    thanks for your help
    Last edited by cyborg; Sep 3rd, 2001 at 02:07 PM.
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  11. #11
    Fanatic Member Mad Compie's Avatar
    Join Date
    Aug 2000
    Location
    Kuurne (Belgium)
    Posts
    553
    Search the net for wu line: these kind of lines are AA.
    Note that all line drawing algorithms are derivates from Jack Bresenham's basic line drawing algorithm.

    Here are some links to visualize this thread...

    http://freespace.virgin.net/hugo.eli...s/x_wuline.htm

    A nice tutorial at: http://www.cs.unc.edu/~mcmillan/comp...re6/Lines.html

  12. #12
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    Mad Compie, are those links to C++ examples? I'd love to see a VB implementation of this
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  13. #13
    Frenzied Member
    Join Date
    Jun 2000
    Location
    England, Buckingham
    Posts
    1,341
    One of thos is C++ (the one with things like int etc) the other is some freaky i dont know. A vb version shouldnt be that hard to do.

  14. #14
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    Well, what I really need is an algorythm to draw lines... simple, non-AA lines

    It's for my lights system, it's coming along pretty good but it would be better if I had a faster algorythm
    Basically I find the offset for each step of the rays each light casts (each ray is just a line, it lights up things 'till it hits a wall) using trig, and then use the old linex=linex+xoffset (same thing for the y) algorythm, which is a bit slow... can anyone help?
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  15. #15
    Fanatic Member Mad Compie's Avatar
    Join Date
    Aug 2000
    Location
    Kuurne (Belgium)
    Posts
    553
    Here some code to apply Jack Bresenham's non-AA line algorithm:

    I rewrote it from C (as seen in http://www.cs.unc.edu/~mcmillan/com...ure6/Lines.htmlmy ) to VB:

    PHP Code:

    Private Sub Form_Load()
      
    Me.ScaleMode vbPixels
    End Sub

    Public Sub lineBresenham(ByVal x0 As IntegerByVal y0 As IntegerByVal x1 As IntegerByVal y1 As IntegerByVal Color As Long)
      
    Dim dY       As Integer
      Dim dX       
    As Integer
      Dim stepX    
    As Integer
      Dim stepY    
    As Integer
      Dim Fraction 
    As Integer
      
      dY 
    y1 y0
      dX 
    x1 x0
            
      
    If (dY 0Then
       dY 
    = -dY
       stepY 
    = -1
      
    Else
       
    stepY 1
      End 
    If
      If (
    dX 0Then
        dX 
    = -dX
        stepX 
    = -1
      
    Else
        
    stepX 1
      End 
    If
      
    dY dY 2
      dX 
    dX 2

      Me
    .PSet (x0y0), Color
      
            
    If (dX dYThen
              Fraction 
    dY - (dX 2)
              While (
    x0 <> x1)
                If (
    Fraction >= 0Then
                  y0 
    y0 stepY
                  Fraction 
    Fraction dX
                End 
    If
                
    x0 x0 stepX
                Fraction 
    Fraction dY
                Me
    .PSet (x0y0), Color
              Wend
            
    Else
              
    Fraction dX - (dY 2)
              While (
    y0 <> y1)
                If (
    Fraction >= 0Then
                  x0 
    x0 stepX
                  Fraction 
    Fraction dY
                End 
    If
                
    y0 y0 stepY
                Fraction 
    Fraction dX
                Me
    .PSet (x0y0), Color
              Wend
            End 
    If
    End Sub

    Private Sub Form_MouseDown(Button As IntegerShift As IntegerAs SingleAs Single)
      
    lineBresenham XYRnd Me.ScaleWidthRnd ScaleHeightRnd * &HFFFFFF
    End Sub 
    Last edited by Mad Compie; Sep 9th, 2001 at 06:07 AM.

  16. #16
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    Thanks
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width