i am attempting to make a triangle using bresenham line drawing algorithm, so far I have the cord for a line but it comes up with errors:
error C2449: found ‘{’ at file scope (missing function header?)
error C2059: syntax error : ‘}’
Error executing cl.exe.
Casn anyone help me at least getting the line working and if possible tell me how i will then go on to complete the triangle. here is my code so far… i need to have it done by tonight if possible so im desperate it just refuses to work:
#include <stdlib.h>
#include <math.h>
#include <GL/glut.h>
int dx,dy;
int main();
{
public void lineBresenham(int x0, int y0, int x1, int y1, Color color) {
int pix = color.getRGB();
int dy = y1 - y0;
int dx = x1 - x0;
int stepx, stepy;
if (dy < 0) { dy = -dy; stepy = -1;
} else { stepy = 1;
}
if (dx < 0) { dx = -dx; stepx = -1;
} else { stepx = 1;
}
dy <<= 1; // dy is now 2dy
dx <<= 1; // dx is now 2dx
raster.setPixel(pix, x0, y0);
if (dx > dy) {
int fraction = dy - (dx >> 1); // same as 2*dy - dx
while (x0 != x1) {
if (fraction >= 0) {
y0 += stepy;
fraction -= dx; // same as fraction -= 2*dx
}
x0 += stepx;
fraction += dy; // same as fraction -= 2*dy
raster.setPixel(pix, x0, y0);
}
} else {
int fraction = dx - (dy >> 1);
while (y0 != y1) {
if (fraction >= 0) {
x0 += stepx;
fraction -= dy;
}
y0 += stepy;
fraction += dx;
raster.setPixel(pix, x0, y0);
}
}
}
}