CG
CG
#include<stdio.h>
#include<GL/glut.h>
Int x1,Y1,x2,y2;
Void bres_general()
glClearColor(1.0,1.0,1.0,0);
glColor3f(0.0,0.0,0.0);
glOrtho(0,640,0,480,0,480);
dx = abs(x2 – x1);
dy = abs(y2 – Y1);
s1 = sign(x2-x1);
s2 = sign(y2-Y1);
glClear(GL_COLOR_BUFFER_BIT);
d = 2 * dy – dx;
x = x1;
y = Y1;
glBegin(GL_POINTS);
int i;
glVertex2i(x,y);
while(d >= 0)
If(swap) x = x + s1;
Else
Y = y + s2;
D = d – 2* dx;
If(swap) y = y + s2;
Else x = x + s1;
D = d + 2 * dy;
glEnd();
glFlush();
Void init() {
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowPosition(200,200);
glutInitWindowSize(780, 640);
glutCreateWindow(“Bresenham Line”);
Scanf(“%d%d”,&x1,&Y1);
Scanf(“%d%d”,&x2,&y2);
glutInit(&argc, argv);
init();
glutDisplayFunc(bres_general);
glutMainLoop();
return 0;