#include #include #include #include float round_value(float v) { return floor(v + 0.5); } void LineDDA(void) { //set line coordinates double X1, Y1, X2, Y2; X1 = Y1 = 50; X2 = 300; Y2 = 200; double dx=(X2-X1), dy = (Y2-Y1), steps; float xInc, yInc, x=X1, y=Y1; /* Find out whether to increment x or y */ steps=(abs(dx)>abs(dy)) ? (abs(dx)) : (abs(dy)); xInc=dx/(float)steps; yInc=dy/(float)steps; /* Clears buffers to preset values */ glClear(GL_COLOR_BUFFER_BIT); /* Plot the points */ glBegin(GL_POINTS); /* Plot the first point */ glVertex2d(x,y); int k; /* For every step, find an intermediate vertex */ for(k=0; k