#include<GL/glut.h>
#include<stdio.h>
#include<stdlib.h>
void draw(int x ,int y){
glBegin(GL_POINTS);
glColor3f(0,1,0);
glVertex2i(x,y);
glEnd();
}
void lineSe(){
float x0 = 0,y0= 0;
float xf= 500,yf=500;
int step = (abs(x0-xf)>abs(y0-yf)?abs(x0-xf):abs(y0-yf) );
int p=-1;
int dx = abs(x0-xf);
int dy = abs(y0-yf);
if(dx>dy){
p=2*dy-dx;
while(x0 != xf && y0 != yf){
draw(x0,y0);
if(p<0){
x0+=1;
p+=2*dy;
}
else {
x0+=1;
y0+=1;
p+=2*dy-2*dx;
}
}
}else{
p=2*dx-dy;
while(x0 != xf && y0 != yf){
draw(x0,y0);
if(p<0){
y0+=1;
p+=2*dx;
}
else {
x0+=1;
y0+=1;
p+=2*dx-2*dy;
}
}
}
glFlush();
}
void Init(){
glClearColor(1.0,1.0,1.0,0.0);
glClear(GL_COLOR_BUFFER_BIT);
gluOrtho2D(-640,640,-480,480);
lineSe();
}
int main(int argc ,char ** argv){
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE );
glutInitWindowPosition(100,100);
glutInitWindowSize(800,800);
glutCreateWindow("BRESENHAM Line");
Init();
glutDisplayFunc(lineSe);
glutMainLoop();
return 0;
}