#include "timer.h" #define fb_width 1024 #define fb_height 1024 static char surface [ fb_width * fb_height ]; void drawPixel ( unsigned x, unsigned y ) { *(surface + y * fb_width + x) = 1; } void bresenham ( unsigned x1, unsigned y1, unsigned x2, unsigned y2 ) { unsigned x, y; int dx, dy; int incx, incy; int balance; if ( x2 >= x1 ) { dx = x2 - x1; incx = 1; } else { dx = x1 - x2; incx = -1; } if (y2 >= y1) { dy = y2 - y1; incy = 1; } else { dy = y1 - y2; incy = -1; } x = x1; y = y1; if ( dx >= dy ) { dy <<= 1; balance = dy - dx; dx <<= 1; while ( x != x2 ) { drawPixel ( x, y ); if ( balance >= 0 ) { y += incy; balance -= dx; } balance += dy; x += incx; } drawPixel ( x, y ); } else { dx <<= 1; balance = dx - dy; dy <<= 1; while (y != y2) { drawPixel ( x, y ); if ( balance >= 0 ) { x += incx; balance -= dy; } balance += dx; y += incy; } drawPixel ( x, y ); } } #define loops 1 int main ( ) { unsigned a; unsigned loop, z; START_TIMER ( ); // for ( loop = 0; loop < loops; loop ++ ) { for ( z = 0; z < fb_width; z++ ) { // Draws in all directions bresenham ( 0,0, fb_height - 1, z ); bresenham ( 0,0, z, fb_height - 1 ); bresenham ( fb_height-1,0, z,fb_height - 1 ); bresenham ( fb_height-1,0, 0,z ); bresenham ( fb_height-1,fb_height-1, 0, z ); bresenham ( fb_height-1,fb_height-1, z, 0 ); bresenham ( 0,fb_height-1, z, 0 ); bresenham ( 0,fb_height-1, fb_height-1, z ); } // } STOP_TIMER ( ); return 0; }