Colouring a surface

I want to draw a surface where each cell (quads) has a different color. However I want to use “Buffer objects” to accelerate the render.

I used glColorPointer, this assigned a color to each vertex, but I want assigned a color to each cell; each vertex would have 4 diferent colors (depending on the color of the face to colorize).

Please a need help!

Hmm, I can think of a couple of ways (none of which is very satisfying and/or straightforward, hope somebody points out something easier that I’m missing :wink: ):

  1. you can repeat the positions four times, each with a different color. The basic problem here is that a vertex is a tuple of properties (position, normal, color, tex coords, etc.) and you can only reuse one if all properties match - since you want different colors at each use that does not work.

  2. you could use a texture storing the color pattern you want on the surface choosing the texture coordinates carefully to have each pixel of the texture map to a quad.

  3. use a geometry shader to generate the quads from points. As input you’d have position, orientation (a quaternion), width & height, and color of the quad.

A solution could be to send in a vertex attribute per vertex so that each vertex has a FaceID (all 4 verticies of a quad would all have the same faceID).
In a vertex shader look up the faceID in a TextureBufferObject (or UniformArray or UniformBufferObject) and colour the vertex without linear interpolation according to the lookup.

Thanks to both…

I will try to use TextureBufferObject, or create four copies of the vertex with diferents colors. Later I will tell you my experience