Table of Contents Glide Programming Guide



Download 6.22 Mb.
Page25/106
Date03.02.2023
Size6.22 Mb.
#60547
1   ...   21   22   23   24   25   26   27   28   ...   106
GLIDEPGM

4Triangles


The triangle is the basic Glide rendering primitive. The Glide function grDrawTriangle() renders an arbitrarily oriented triangle with vertices a, b, and c to the screen.
void grDrawTriangle( const GrVertex *a, const GrVertex *b, const GrVertex *c )

Triangles are rendered with the following filling rules:



A pixel center is within a triangle if it is inside all three of the edges. When a pixel center lies exactly on an edge, it is inside the triangle if the edge is considered inside, and outside otherwise. Left edges are in, right edges are out. Horizontal edges with the smaller y value are in; those with a larger y value are out.
Figure Rendering Primitives.2 gives an example. Eight triangles are shown, all sharing a common vertex. Only one of the triangles renders the pixel whose center is the shared vertex. Can you guess which one?
The shared vertex is part of the “right edge” of triangles A, H, G, and F, and hence outside. It is part of the “top edge” (since the origin is in the lower left) of triangles G, F, E and D, and thus outside them as well. In triangle B, the vertex is on one inside edge and one outside edge and hence is considered outside the triangle. Only in triangle C does the vertex lie on two “inside” edges and thus lies inside the triangle.

1Clipping a Triangle


Recall from the clipping window discussion above that the hardware clipping implemented by Voodoo Graphics is at the end of the rendering pipeline: a pixel will incur all the rendering cost only to be discarded just before being written to the frame buffer. An alternative solution is to use host bandwidth to clip the triangle and process only the pixels that will be displayed. The Glide Utility Library provides just such a function. guDrawTriangleWithClip() uses Sutherland-Hodgman clipping [SUTH74] to clip the triangle to the rectangle specified by grClipWindow() and then draws the resulting polygon.
void guDrawTriangleWithClip( const GrVertex *a, const GrVertex *b, const GrVertex *c )

Figure Rendering Primitives.2 Pixel rendering.


Which of the eight triangles shown in diagram (a) will render the pixel at the common vertex? In diagram (b), solid edges are considered inside the triangle while dotted edges are outside. The top row of diagrams are drawn with the origin in the lower left corner. The bottom row represent the other possibility: the origin is in the upper left corner. The two pairs of diagrams are mirror images of each other.



Download 6.22 Mb.

Share with your friends:
1   ...   21   22   23   24   25   26   27   28   ...   106




The database is protected by copyright ©ininet.org 2024
send message

    Main page