### Sample Wu Antialiasing {#Heading5} The true test of any antialiasing technique is how good it looks, so let's have a look at Wu antialiasing in action. Listing 42.1 is a C implementation of Wu antialiasing. Listing 42.2 is a sample program that draws a variety of Wu-antialiased lines, followed by non-antialiased lines, for comparison. Listing 42.3 contains **DrawPixel()** and **SetMode()** functions for mode 13H, the VGA's 320x200 256-color mode. Finally, Listing 42.4 is a simple, non-antialiased line-drawing routine. Link these four listings together and run the resulting program to see both Wu-antialiased and non-antialiased lines. **LISTING 42.2 L42-2.C** /* Sample line-drawing program to demonstrate Wu antialiasing. Also draws * non-antialiased lines for comparison. * Tested with Borland C++ in C compilation mode and the small model. */ #include #include void SetPalette(struct WuColor *); extern void DrawWuLine(int, int, int, int, int, int, unsigned int); extern void DrawLine(int, int, int, int, int); extern void SetMode(void); extern int ScreenWidthInPixels; /* screen dimension globals */ extern int ScreenHeightInPixels; #define NUM_WU_COLORS 2 /* # of colors we'll do antialiased drawing with */ struct WuColor { /* describes one color used for antialiasing */ int BaseColor; /* # of start of palette intensity block in DAC */ int NumLevels; /* # of intensity levels */ int IntensityBits; /* IntensityBits == log2 NumLevels */ int MaxRed; /* red component of color at full intensity */ int MaxGreen; /* green component of color at full intensity */ int MaxBlue; /* blue component of color at full intensity */ }; enum {WU_BLUE=0, WU_WHITE=1}; /* drawing colors */ struct WuColor WuColors[NUM_WU_COLORS] = /* blue and white */ {{192, 32, 5, 0, 0, 0x3F}, {224, 32, 5, 0x3F, 0x3F, 0x3F}}; void main() { int CurrentColor, i; union REGS regset; /* Draw Wu-antialiased lines in all directions */ SetMode(); SetPalette(WuColors); for (i=5; i /* Screen dimension globals, used in main program to scale. */ int ScreenWidthInPixels = 320; int ScreenHeightInPixels = 200; /* Mode 13h draw pixel function. */ void DrawPixel(int X, int Y, int Color) { #define SCREEN_SEGMENT 0xA000 unsigned char far *ScreenPtr; FP_SEG(ScreenPtr) = SCREEN_SEGMENT; FP_OFF(ScreenPtr) = (unsigned int) Y * ScreenWidthInPixels + X; *ScreenPtr = Color; } /* Mode 13h mode-set function. */ void SetMode() { union REGS regset; /* Set to 320x200 256-color graphics mode */ regset.x.ax = 0x0013; int86(0x10, ®set, ®set); }