Vertex Colors

Let’s take a closer look at specifying color data with a vertex. Recall from Chapter 1 that vertices can have multiple data values associated with them, and colors can be among them. As with any other vertex data, the color data must be stored in a vertex-buffer object. In Example 4.1, we interleave the vertices’ color and position data, and use an integer-valued type to illustrate having OpenGL normalize our values.

Example 4.1. Specifying Vertex Color and Position Data: gouraud.cpp

/////////////////////////////////////////////////////////////////////////// Gouraud.cpp/////////////////////////////////////////////////////////////////////////#include <iostream>using namespace std;#include "vgl.h"#include ...

Get OpenGL Programming Guide: The Official Guide to Learning OpenGL, Version 4.3, Eighth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.