/******************************************************************* Template for your Triangle Drawing Function ******************************************************************** Author: Stan Sclaroff Comments: Template for your function that draws a triangle. given the triangle points in the Vertex tri[3]. if(renderFlags == 0) then render triangle using only first vertex color (flat shading) else if(renderFlags & SMOOTH_SHADING_BIT) != 0) then render triangle using smooth shading else if((renderFlags & TEXTURE_MAPPING_BIT) != 0) then render using texture map look up (u,v) Note texture mapping is only required for CS680 students. Provided for CS480/CS680 programming assignment #1. ********************************************************************/ #include "types.h" #include "funcs.h" #define ROUND(A) ((int) ((A)+0.5)) void drawTriangle(Vertex tri[3], int renderFlags) { /* Write a triangle rasterizer that uses your drawLine function to fill scanlines inside the triangle. Your algorithm must fill _scanlines_. Note that in the vertex structure (defined in "types.h"): x,y are the vertex positions, color is the vertex (r,g,b) color (u,v are the texture map positions) you only need u and v if you implement the texture mapping Hints: First sort the triangle vertices by their Y value. Then scan the upper half and the lower half of the triangle separately. Be careful of horizontal edges (empty upper or lower triangle). */ /* The following three lines are meant as a demo to show the triangle. They should be removed once you write your triangle rasterizer here */ setPixel(ROUND(tri[0].x), ROUND(tri[0].y), tri[0].color); setPixel(ROUND(tri[1].x), ROUND(tri[1].y), tri[1].color); setPixel(ROUND(tri[2].x), ROUND(tri[2].y), tri[2].color); }