Reputation: 512
I would like to use a texture similar to a Photoshop style brush (example: http://designblurb.com/wp-content/uploads/2008/11/grungy-watercolor-brushes.jpg), and allow the user to choose a color for it, so when it is drawn to the screen the grey's black's become colorized by the user's selection.
Does anyone know the best way to achieve this? Are there texture environment variables that can do this?
Any information is greatly appreciated.
Upvotes: 0
Views: 1625
Reputation: 45948
Well, it just comes down to combining the texture's color with some constant color. So you have greyscale texture (be it either a GL_RGB
texture with all components of a color having the same value, or just a GL_LUMINANCE
texture). The actual combination of both colors depends on your OpenGL ES version.
In ES 1 you just use the GL_MODULATE
texture environment to multiply the texture color with the object's/vertex' color (either computed by lighting or set by glColor
or glColorPointer
if lighting is disabled, which seems your case):
glColor(...);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
//draw a textured object
In ES 2 you of course have to do it yourself in the fragment shader:
uniform sampler2D tex;
uniform vec4 color;
varying vec2 texCoord;
void main()
{
gl_FragColor = color * texture2D(tex, texCoord).r;
}
If all these things don't tell you anything (depending on your version), then you should probably delve a bit depper into the basics of OpenGL ES and combining a texture with a constant color is your least problem.
Upvotes: 3