DDA LINE Algorithm
DDA LINE Algorithm
#include <cmath>
#include <GL/glut.h>
float round_value(float v) {
return floor(v + 0.5);
}
void LineDDA() {
double dx = (X2 - X1);
double dy = (Y2 - Y1);
double steps;
float xInc, yInc, x = X1, y = Y1;
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POINTS);
glVertex2d(x, y);
glEnd();
glFlush();
}
void Init() {
glClearColor(1.0, 1.0, 1.0, 0);
glColor3f(0.0, 0.0, 0.0);
gluOrtho2D(0, 640, 0, 480);
}
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowPosition(100, 100);
glutInitWindowSize(640, 480);
glutCreateWindow("DDA Line Drawing - C++ OpenGL");
Init();
glutDisplayFunc(LineDDA);
glutMainLoop();
return 0;
}