I've been having the hardest time trying to get this code to work. I tried to take the pseudo-code from wikipedia and turn it into C++ code I can use for a project. bufPixel() draws a pixel on (buffer,x,y with attributes). When it draws the line, it appears to only draw straight down each time, as in, no matter what line, it will always draw a slope of 1 or -1. Thanks in advance.
Code:
Code:
void bufLine(CHAR_INFO* buffer,short x0,short y0,short x1,short y1,WORD attributes)
{
CHAR_INFO letter;
letter.Char.AsciiChar = ' ';
letter.Attributes = attributes;
bool steep = abs(y1 - y0) > abs(x1 - x0);
SHORT a;
if (steep)
{
a = x0; x0 = y0; y0 = a;
a = x1; x1 = y1; y1 = a;
}
if (x0 > x1)
{
a = x0; x0 = x1; x1 = a;
a = y0; y0 = y1; y1 = a;
}
int deltax = x1 - x0;
int deltay = abs(y1 - y0);
float error = 0;
float deltaerr = deltay / deltax;
int ystep;
if (y0 < y1)
ystep = 1;
else
ystep = -1;
int y = y0;
for (int x = x0;x < x1;x++)
{
if (steep)
bufPixel(buffer,y,x,attributes);
else
bufPixel(buffer,x,y,attributes);
error = error + deltaerr;
if (error >= 0.5)
{
y += ystep;
error = error - 1;
}
}
}