It's [i]almost[/I] working properly now... check out the screenshot (2 instances running side by side)
The only flaw are some of the Vertex are being Plotted at the Top of the Screen... trying to figure out what 'special case' is causing it to hack in a fix., but other than that... it works
Sync On : Sync Rate 0
Disable Escapekey
Type TimerFormat
_Prev As Dword
_Next As Dword
_Delta As Dword
_Tock As Dword
_Tick As Float
EndType
Global Clock As TimerFormat
Clock._Tick = 16
Global bAntiAlias As Boolean
Do
Cls RGB(R,G,B)
Ink (Not Point(0,0)), Point(0,0)
C = Not Point(0,0)
Lock Pixels
If bAntiAlias <> Null
AntiAlias$ = "True"
FnLineAA(250,47,449,175,C)
FnLineAA(449,175,203,306,C)
FnLineAA(203,306,250,47,C)
FnLineAA(186,200,345,445,C)
FnLineAA(345,445,60,376,C)
FnLineAA(60,376,186,200,C)
FnLineAA(440,230,555,410,C)
FnLineAA(555,410,385,400,C)
FnLineAA(385,400,440,230,C)
Else
AntiAlias$ = "False"
FnLine(250,47,449,175,C)
FnLine(449,175,203,306,C)
FnLine(203,306,250,47,C)
FnLine(186,200,345,445,C)
FnLine(345,445,60,376,C)
FnLine(60,376,186,200,C)
FnLine(440,230,555,410,C)
FnLine(555,410,385,400,C)
FnLine(385,400,440,230,C)
EndIf
Unlock Pixels
Clock._Prev = Clock._Next
Clock._Next = Timer()
Clock._Delta = Clock._Next - Clock._Prev
Inc Clock._Tock, Clock._Delta
If Clock._Tock > Clock._Tick
Clock._Tock = 0
Inc Frame, 1
EndIf
If Frame >= 60
//R = RND(255) : G = RND(255) : B = RND(255)
Frame = 0
EndIf
If Scancode() = 57
If bHeld = 0
bAntiAlias = Not bAntiAlias
EndIf
EndIf
Text 10, 10, "AntiAlias: " + AntiAlias$
Text 10, 30, "RED: " + Str$(FnRed(Point(0,0))) + " Green: " + Str$(FnGreen(Point(0,0))) + " Blue: " + Str$(FnBlue(Point(0,0)))
If Escapekey() Then Exit
If Scancode() <> 0 Then bHeld = 1 Else bHeld = 0
FastSync 1
Loop
End
Function FnRed( C )
C = (C && 0xFF0000) >> 16
EndFunction C
Function FnGreen( C )
C = (C && 0x00FF00) >> 8
EndFunction C
Function FnBlue( C )
C = (C && 0x0000FF)
EndFunction C
Function FnColour( R, G, B )
Local C
C = (R || (G << 8) || (B << 16))
EndFunction C
Function FnPlotB( X, Y, C, B# )
Rem // Colour isn't correct for certain Hues, not sure why
Local S, F#
S = Point( X, Y )
C = FnColour(FnRed(C) * B# + (S And 0xFF) * (1 - B#), FnGreen(C) * B# + (S >> 8 And 0xFF) * (1 - B#), FnBlue(C) * B# + (S >> 16 And 0xFF) * (1 - B#))
Dot X, Y, C
EndFunction
Function FnPlot( X, Y, C )
Dot X, Y, C
EndFunction
Function FnFracPart( X# )
X# = X# - Floor(X#)
EndFunction X#
Function FnInvFracPart( X# )
X# = 1.0 - FnFracPart(X#)
EndFunction X#
Function FnRound( X# )
X# = Int(X# + 0.5)
EndFunction X#
Function FnLineAA( X1#, Y1#, X2#, Y2#, Colour )
Local DX#, DY#, XEND#, YEND#, GRAD#, T#
Local YF#, XGAP#, IX1#, IY1#, IX2#, IY2#
Local X#, STEEP
DX# = X2# - X1#
DY# = Y2# - Y1#
STEEP = Abs(DX#) < Abs(DY#)
If STEEP
T# = X1# : X1# = Y1# : Y1# = T#
T# = X2# : X2# = Y2# : Y2# = T#
T# = DX# : DX# = DY# : DY# = T#
EndIf
If X2# < X1#
T# = X1# : X1# = X2# : X2# = T#
T# = Y1# : Y1# = Y2# : Y2# = T#
EndIf
GRAD# = DY# / DX#
// first point
XEND# = FnRound(X1#)
YEND# = Y1# + GRAD# * (XEND# - X1#)
XGAP# = FnInvFracPart(X1# + 0.5)
IX1# = XEND#
IY1# = Int(YEND#)
If Not STEEP
FnPlotB(Int(IX1#), Int(IY1#), Colour, FnInvFracPart(YEND#) * XGAP#)
FnPlotB(Int(IX1#), Int(IY1#) + 1, Colour, FnFracPart(YEND#) * XGAP#)
Else
FnPlotB(Int(IY1#), Int(IX2#), Colour, FnInvFracPart(YEND#) * XGAP#)
FnPlotB(Int(IY1#) + 1, Int(IX2#), Colour, FnFracPart(YEND#) * XGAP#)
EndIf
YF# = YEND# + GRAD#
// end point
XEND# = FnRound(X2#)
YEND# = Y2# + GRAD# * (XEND# - X2#)
XGAP# = FnFracPart(X2# + 0.5)
IX2# = XEND#
IY2# = Int(YEND#)
If Not STEEP
FnPlotB(Int(IX2#), Int(IY2#), Colour, FnInvFracPart(YEND#) * XGAP#)
FnPlotB(Int(IX2#), Int(IY2#) + 1, Colour, FnFracPart(YEND#) * XGAP#)
Else
FnPlotB(Int(IY2#), Int(IX2#), Colour, FnInvFracPart(YEND#) * XGAP#)
FnPlotB(Int(IY2#) + 1, Int(IX2#), Colour, FnFracPart(YEND#) * XGAP#)
EndIf
// draw line
If Not STEEP
For X# = IX1# + 1 To IX2# - 1
FnPlotB(Int(X#), Int(YF#), Colour, FnInvFracPart(YF#))
FnPlotB(Int(X#), Int(YF#) + 1, Colour, FnFracPart(YF#))
YF# = YF# + GRAD#
Next
Else
For X# = IX1# + 1 To IX2# - 1
FnPlotB(Int(YF#), Int(X#), Colour, FnInvFracPart(YF#))
FnPlotB(Int(YF#) + 1, Int(X#), Colour, FnFracPart(YF#))
YF# = YF# + GRAD#
Next
EndIf
EndFunction
Function FnLineLow( AX, AY, BX, BY, C )
Local X, Y, YI, DX, DY, D
DX = BX - AX
DY = BY - AY
YI = 1
If DY < 0
YI = -1
DY = -DY
EndIf
D = 2 * DY - DX
Y = AY
For X = AX To BX
FnPlot( X, Y, C )
If D > 0
Inc Y, YI
Dec D, (2 * DX)
EndIf
Inc D, (2 * DY)
Next X
EndFunction
Function FnLineHigh( AX, AY, BX, BY, C )
Local X, Y, XI, DX, DY, D As Integer
DX = BX - AX
DY = BY - AY
XI = 1
If DX < 0
XI = -1
DX = -DX
EndIf
D = 2 * DX - DY
X = AX
For Y = AY To BY
FnPlot( X, Y, C )
If D > 0
Inc X, XI
Dec D, (2 * DY)
EndIf
Inc D, (2 * DX)
Next Y
EndFunction
Function FnLine( AX, AY, BX, BY, C )
If Abs(BY - AY) < Abs(BX - AX)
If AX = BX
For Y = AY To BY
FnPlot( AX, Y, C )
Next
Else
If AX > BX
FnLineLow( BX, BY, AX, AY, C )
Else
FnLineLow( AX, AY, BX, BY, C )
EndIf
EndIf
Else
If AY = BY
For X = AX To BX
FnPlot( X, AY, C )
Next
Else
If AY > BY
FnLineHigh( BX, BY, AX, AY, C )
Else
FnLineHigh( AX, AY, BX, BY, C )
EndIf
EndIf
EndIf
EndFunction
Next step is to handle a Fill Routine (for the Shape Areas) … this will be for handling Polygon (Triangle / Quad) Rendering.
Oh., and I still need to sort out the Colour Displacement with the Anti-Aliased Edges but the code is still in there (just need to uncomment) to cycle through a Foreground and a Negative Background., it's a crass approach but eh, was just for testing purposes.