Write a procedure to draw a line in OpenGL? Describe Painter’s algorithm.

This answer is restricted. Please login to view the answer of this question.

Login Now

In OpenGL, the term line refers to a line segment. There are easy ways to specify a connected In all cases the lines constituting the connected series are specified in terms of the vertices at their endpoints.

Below is the image of two connected series of line segments.

User Loaded Image | CSIT Guide

With OpenGL, we can specify lines with different widths and lines that are stippled in various ways-dotted, dashed and so on. Drawing a line with OpenGL is apparently quite simple using the following code.

    glVertex2i(x0, y0);
    glVertex2i(x1, y1);

Painter’s Algorithm:

This method uses both object space and image space method. The depth sorting method performs following two basic functions.

  1. The surface are sorted in order of decreasing depth
  2. The surface are scan-converted in order, starting with the surface of greatest depth.

The intensity values for farthest surface are entered into the refresh buffer. The farthest polygon is displayed first, then the second farthest polygon and so on. After all surfaces have been processed, the refresh buffer stores the final intensity values for all visible surfaces.

When there are a few objects in the scene, then this method can be very fast. However, as the number of objects increases, the sorting process can become very complex and time consuming.


  1. The sorting computation is very fast, so quick calculation of image, display is possible.
  2. The finished image data remains object based and can be edited in terms of line weight, exploded views etc.
  3. It will also print at the highest resolution available an devices such as postscript laser printers.


  1. Different polygons may have same depth
  2. The nearest polygon could also be farthest
  3. We cannot use simple depth-sorting to remove the hidden surfaces in the images.
If you found any type of error on the answer then please mention on the comment or report an answer or submit your new answer.
Leave your Answer:

Click here to submit your answer.

  Loading . . .