draw a long line segment using i dda line drawing


Draw a long line segment using (i) DDA line drawing algorithm (ii) Bresenham line drawing algorithm (iii) OpenGL function using GL_LINES.  Observe if DDA line segment deflects from Bresenham line segment or the graphics library line segment. 

Answer: Implementation of Bresenham and DDA algorithm is already given on page 20-21 of this unit.  Use the code to draw a line segment (10, 20) - (1020, 700) using both the algorithms.  Further, we draw the same line segment by adding the following code in the RenderScene( ) function of the code using the following OpenGL library function.    

glBegin(GL_LINES);

   glVertex2i(1020,700);

   glVertex2i(10,20);

   glEnd();  

Use a different colour for each of the three codes. Accordingly code of RenderScene( ) will be modified as follows:   

void RenderScene(void)

{

glClear(GL_COLOUR_BUFFER_BIT);

glColour3f(1.0f, 0.0f, 0.0f);    

bresenham(10,20,1020,700);//Bresenham line segment with RED

   glColour3f(0.0f, 1.0f, 0.0f);        

  dda(10,20,1020,700); //dda line segment with GREEN

  glColour3f(1.0f, 1.0f, 1.0f);        

  glBegin(GL_LINES);

   glVertex2i(1020,700);

   glVertex2i(10,20);

  glEnd(); //OpenGl Line segment with WHITE

        glFlush();   

}

On present day systems with very high accuracy on floating point calculations all the three line segments are plotting almost the same line segment. However, if you run the same program on an older system, you would find that the pixels generated by DDA algorithm are slightly away from the two line segments that have been generated using Bresenham algorithm and OpenGL function. The OpenGL function and Bresenham algorithm produce almost the same line segments.

Request for Solution File

Ask an Expert for Answer!!
Computer Graphics: draw a long line segment using i dda line drawing
Reference No:- TGS0417503

Expected delivery within 24 Hours