Anti-aliased 2D graphics
Posted: Mon Feb 23, 2015 10:59 am
To quickly anti-alias all 2D drawing, all you really need to do for satisfactory results is double the size of everything created, then shrink it back to 100% size afterwards.
To that end, it seems to me that wrapping the 2D drawing commands in macros to double everything is the easiest way, and this means the drawing speed is always exactly the same as the normal 2D drawing commands; except for the final single step of shrinking it to 100%. So for general image displays (think charts as opposed to games), the speed is perfectly acceptable.
Here's some wrapping to show what I mean. As you can see, the AA commands are anti-aliased versions of the normal 2D commands, so they're easy to drop right in when AA is needed. You just have to finish all drawing of the AA image with the Finish_AA() command, which always goes after the StopDrawing() command.
Anyway, it's what I'm using and I like it, so I hope it helps/inspires others.

To that end, it seems to me that wrapping the 2D drawing commands in macros to double everything is the easiest way, and this means the drawing speed is always exactly the same as the normal 2D drawing commands; except for the final single step of shrinking it to 100%. So for general image displays (think charts as opposed to games), the speed is perfectly acceptable.
Here's some wrapping to show what I mean. As you can see, the AA commands are anti-aliased versions of the normal 2D commands, so they're easy to drop right in when AA is needed. You just have to finish all drawing of the AA image with the Finish_AA() command, which always goes after the StopDrawing() command.
Anyway, it's what I'm using and I like it, so I hope it helps/inspires others.


Code: Select all
Macro CreateImage_AA(img,w,h,depth=24,color=0)
CreateImage(img,w*2,h*2,depth,color)
EndMacro
Macro Circle_AA(x,y,radius,color=#PB_Default)
Circle(x*2,y*2,radius*2,color)
EndMacro
Macro LineXY_AA(x1,y1,x2,y2,color=#PB_Default)
LineXY(x1*2,y1*2,x2*2,y2*2,color)
EndMacro
Macro Finish_AA(img)
ResizeImage(img,ImageWidth(img)/2,ImageHeight(img)/2)
EndMacro
OpenWindow(0,0,0,680,280,"Anti-Alias Macros",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
; Normal 2D circle with line.
CreateImage(1,320,240,32,#White)
StartDrawing(ImageOutput(1))
DrawingMode(#PB_2DDrawing_Outlined)
Circle(160,120,100,#Blue)
LineXY(0,0,320,240,#Red)
StopDrawing()
; Anti-aliased 2D circle with line.
CreateImage_AA(2,320,240,32,#White)
StartDrawing(ImageOutput(2))
DrawingMode(#PB_2DDrawing_Outlined)
Circle_AA(160,120,100,#Blue)
LineXY_AA(0,0,320,240,#Red)
StopDrawing()
Finish_AA(2) ; Required when AA drawing is done.
ImageGadget(1,10,10,320,240,ImageID(1))
ImageGadget(2,350,10,320,240,ImageID(2))
Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow