Shapes and Scan Converting
We are all familiar with basic shapes such as lines and polygons. They are easy enough to visualize and represent on paper. But how do we draw them on the computer? The trick is in finding the right pixels to turn on!
The process by which an idealized shape, such as a line or a circle, is transformed into the correct "on" values for a group of pixels on the computer is called scan conversion and is also referred to as rasterizing.
Over the years, several algorithms have been devised to make the process of scan converting basic geometric entities such as lines and circles simple and fast.
The most popular line-drawing algorithm is the midpoint-line algorithm. This algorithm takes the x- and y- coordinates of a line's endpoints as input and then calculates the x,^-coordinate pairs of all the pixels in between. The algorithm begins by first calculating the physical pixels for each endpoint. An ideal line is then drawn connecting the end pixels and is used as a reference to determine which pixels to light up along the way. Pixels that lie less than 0.5 units from the line are turned on, resulting in the pixel illumination as shown in Fig.1.12.
All graphic packages (OpenGL included) incorporate predefined algorithms to calculate the pixel illuminations for drawing lines.
Basic linear shapes such as triangles and polygons can be defined by a series of lines. A polygon is defined by n number of vertices connected by lines, where n is the number of sides in the polygon. A quadrilateral, which is a special case of a polygon is defined by four vertices, and a triangle is a polygon with three vertices as shown in Fig. 1.13.
To specify the vertices of these shapes in OpenGL, we use the function that we saw earlier:
Post a comment