0% found this document useful (0 votes)
2 views2 pages

Print Format

Uploaded by

zaidkhan226
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Print Format

Uploaded by

zaidkhan226
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Experiment Title: -Bresenham’s Line Drawing algorithm.

Aim: - To implement Bresenham’s Line Drawing algorithm


Program/Source Code:-
#include <GL/glut.h>
#include <stdlib.h>
#include <stdio.h>
float x1, x2, y1, y2;
void display(void) {
float dy, dx, step, x, y, k, Xin, Yin;
dx = x2 - x1;
dy = y2 - y1;
if (abs(dx) > abs(dy)) {
step = abs(dx);
} else {
step = abs(dy);
}
Xin = dx / step;
Yin = dy / step;
x = x1;
y = y1;
glBegin(GL_POINTS);
for (k = 1; k <= step; k++) {
glVertex2i(x, y);
x = x + Xin;
y = y + Yin;
}
glEnd();
glFlush();
}
void init(void) {
glClearColor(0.7, 0.7, 0.7, 0.7);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-100, 100, -100, 100);
}
int main(int argc, char** argv) {
printf("Enter the value of x1: ");
scanf("%f", &x1);
printf("Enter the value of y1: ");
scanf("%f", &y1);
printf("Enter the value of x2: ");
scanf("%f", &x2);
printf("Enter the value of y2: ");
scanf("%f", &y2);
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(500, 500);
glutInitWindowPosition(100, 100);
glutCreateWindow("DDALineAlgo_ZAID_26");
init();
glutDisplayFunc(display);
glutMainLoop();
return 0;
}

Output: -

Experiment Rubric: -
Signature of
Evaluation Criteria Marks
Instructor with Date

Lab Performance

Topic Knowledge

Task Conclusion

Attainment Level (Out of 3)

You might also like