Which shader version you need? (1.0 is enough?)
Did you have the algorithm to load shaders?
//vertex shader
void main()
{
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
gl_TexCoord[0].xy = gl_MultiTexCoord0.xy;
}
// fragment/pixel shader
uniform sampler2D firstGrassTexture;
uniform sampler2D secondGrassTexture;
uniform sampler2D maskTexture;
void main()
{
gl_FragColor = mix(texture2D(firstGrassTexture,gl_TexCoord[0].xy), texture2D(secondGrassTexture,gl_TexCoord[0].xy), texture2D(maskTexture,gl_TexCoord[0].xy).a);
}
you need to do this in your application:
GLhadleARB shaderProgram; // somewhere defined in your application (of course it must be loaded) glUseProgramObjectARB(shaderProgram); glUniform1iARB(glGetUniformLocationARB(shaderProgram,"firstGrassTexture"),0); glUniform1iARB(glGetUniformLocationARB(shaderProgram,"secondGrassTexture"),1); glUniform1iARB(glGetUniformLocationARB(shaderProgram,"maskTexture"),2); glUseProgramObjectARB(0);
The code which was introduced above is a initialization of uniforms setup (so, just call it once).
The next code you need to call each time when you render your object with this shader:
glActiveTextureARB(GL_TEXTURE0_ARB); glBindTexture(...);// here you bind first grass texture glActiveTextureARB(GL_TEXTURE1_ARB); glBindTexture(...);// here you bind second grass texture glActiveTextureARB(GL_TEXTURE2_ARB); glBindTexture(...);// here you bind mask texture glActiveTextureARB(GL_TEXTURE0_ARB); glUseProgramObjectARB(shaderProgram); Draw the mesh glUseProgramObjectARB(0);// disable using shader (maybe you have some object below which you want to draw them without using shaders
Best wishes, FXACE.
Male