I’ve got the following vertex and fragment shaders respectively:
uniform mat4 projMat;
uniform mat4 viewMat;
uniform vec4 modulateColor;
uniform bool isTextureEnabled_vs;
attribute vec4 inVertexPos;
attribute vec4 inVertexColor;
attribute vec2 inTexCoord;
varying vec4 varVertexColor;
varying vec2 varTexCoord;
void main()
{
vec4 pos = inVertexPos;
pos.z = -pos.z;
gl_Position = viewMat * projMat * pos;
varVertexColor = inVertexColor * modulateColor;
if (isTextureEnabled_vs) {
varTexCoord = inTexCoord;
}
}
uniform sampler2D tex0;
uniform bool isTextureEnabled_fs;
varying vec4 varVertexColor;
varying vec2 varTexCoord;
void main()
{
if (isTextureEnabled_fs) {
gl_FragColor = varVertexColor * texture2D(tex0, varTexCoord.st);
} else {
gl_FragColor = varVertexColor;
}
}
When the isTextureEnabled_vs and isTextureEnabled_fs are (true) then everything render fines with correct texture and color. However when set to (false) then the primitives are rendered with incorrect color values which looks random.
In either cases I pass the same attributes and uniform/sampler values and fill up the same vertex buffer with the same data. What could be the problem?
Another question, is it possible to use the same uniform variable in both shaders so that I can have one common name (isTextureEnabled)?
Graphics spec:
OpenGL renderer string: ATI MOBILITY RADEON X1600
OpenGL version string: 2.1.8545 Release
Help appreciated.