Reputation: 677
I am learning OpenGL. At the moment i knew how to define primitives using VBO. I implemented simple class Mesh and from this class some primitives like Square. Now i wanted to learn good way to define colors. I am thinking about using shaders. My idea is to get something like this.
class ColorShader{
public:
static GLuint red = LoadShaders( "SimpleVertexShader.vertexshader", "red.fragmentshader" );
};
But i am not sure is that good way to do. I think that plus of this method is that i will get 30-50% less memory for each triangle. But minus will be that i will need prepare more fragmentshaders.
VertexColor gives me more power to define objects but it consume more memory and I dont like idea settings colors and vertices in the same place.
Upvotes: 0
Views: 155
Reputation: 604
If I understand you correctly, you want to set the color per object instead of per-vertex? I would go with sending a float4 value to the fragment shader for every object in a constant buffer (at least that is what it is called in DirectX). It is really simple and the most basic thing, really.
Edit: http://www.opengl.org/wiki/Uniform_Buffer_Object They are called Uniform buffers in OpenGL.
The basic idea is that you declare a uniform variable in your shader, and get a pointer to it in your c++ code and upload 4 floats there every time you draw an object (or set once and the same color will be used for every object).
Upvotes: 1