Coloring and texturing mesh faces
Thus far, in our OpenGL project, we have implemented simple white mesh rendering. Now, it’s time to add the functionality of coloring and texturing polygons and pixels. The logic is similar to that of vertex coloring and UV mapping, as discussed in Chapter 5, Let’s Light It Up! Though now, when using shaders to do the rendering, the colors are added vertex by vertex and pixel by pixel.
A color is allocated to a vertex via the vertex shader and then passed to the fragment shader. The color for each vertex will specify the color of the pixel representing the vertex, but not the colors in between. Take, for example, the close-up of our teapot model in Figure 18.1:
Figure 18.1: Polygons colored using vertex colors
The colors for each vector are indicated by (a), (b), and (c). This means the fragment shader must interpret what the value for each pixel between the vertices will be. As you can see from Figure 18.1...