Computer Graphics – 14. DDA Line Drawing Algorithm

[wpdm_package id=’1237′]
Sample Input – Draw a line using DDA Line Drawing Algorithm. End points of the line should be accepted using mouse clicks. Use ‘+’ and ‘-‘ to increase and decrease the width of the line. Clear screen using right click.
Sample Ouput –DDA_Line_Drawing

[sourcecode lang=”cpp”]
void dda_draw_line(GLintPoint p1, GLintPoint p2){
GLdouble x=0, y=0;
int dx=(p2.x-p1.x);
int dy=(p2.y-p1.y);
int steps=(abs(dx)>abs(dy)?abs(dx):abs(dy));
GLdouble x_inc=(dx*1.0/steps);
GLdouble y_inc=(dy*1.0/steps);

x=p1.x, y=p1.y;
for(int i=0; i<=steps; i++){

To compile the above program in ubuntu terminal –
# g++ -lGL -lGLU -lglut DDA_Line_Drawing.cpp
# ./a.out

Leave a Reply

Your email address will not be published. Required fields are marked *