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

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.

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.

glBegin(GL_LINES);
glVertex2i(x0, y0);
glVertex2i(x1, y1);
glEnd();

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.