Adding colors to our object

In this part, we will demonstrate how we can use different colors to texture our object. We will use RGB values using a colorBuffer to fetch values from the colors of the vertices. After this, we will enable the color-array client state, and then these colors are rendered together with the vertices in glDrawElements().

Here, we will again use nio's FloatBuffer to declare our colorBuffer variable. Here are the steps we would use to add color to our object:

  1. We declare our colorBuffer variable.
  2. We declare our color array variable.
  3. We copy our color vertices data to our buffer.
  4. Enable our color array.
  5. Define color array buffer.
  6. Disable color array.

Also, since this is a native property of the triangle, we will write ...

Get Learning Android Game Development now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.