View Full Version : Colouring a surface
07-13-2011, 01:40 PM
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!
07-14-2011, 07:30 AM
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 ;) ):
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.
07-14-2011, 09:55 AM
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.
07-15-2011, 11:43 AM
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
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.