ok ive been researching GLSL shaders for a few days now and have progressed pretty well. i used to do Cg but now im switching.
anyway ive been running into some weird issues with the shaders. basically what my shaders are doing is blending between two textures based on a timer. my vertex shader transforms the position of the vertex and sets the 1st and 2nd texture units up for the fragment shader. the fragment shader then takes the two textures, grabs a fragment from each, and then does the follwing equation as the final fragment color: (alpha*tex2)+((1.0-alpha)*tex1). alpha is the uniform variable based on time;
the issue i am having is i can get my first and second texture to add and/or multiply with the correct output. whenever i output only the second texture unit, or multiply it with alpha, i always get the first texture unit. the same happens when i run them through the equation last paragraph.
here is my vertex shader code
void main()
{
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_TexCoord[0] = gl_MultiTexCoord1;
}
here is my fragment shader code
uniform sampler2D texture0, texture1;
uniform float alpha;
void main()
{
vec4 tex1 = texture2D(texture0, gl_TexCoord[0].st);
vec4 tex2 = texture2D(texture1, gl_TexCoord[0].st);
gl_FragColor = (alpha*tex2)+((1.0-alpha)*tex1);
}
here is the code for setting the uniform variables and the shader
GLint tex0, tex1;
GLint alpha;
void SetTestShader()
{
vert_shader.filename = "vp0.vert";
vert_shader.type = GL_VERTEX_SHADER_ARB;
frag_shader.filename = "fp0.frag";
frag_shader.type = GL_FRAGMENT_SHADER_ARB;
LoadGLSLShader(vert_shader);
LoadGLSLShader(frag_shader);
glUseProgramObjectARB(frag_shader.shader_handle);
tex0 = glGetUniformLocationARB(frag_shader.shader_handle, "texture0");
tex1 = glGetUniformLocationARB(frag_shader.shader_handle, "texture1");
//alpha = glGetUniformLocationARB(frag_shader.shader_handle, "alpha");
}
btw when i uncomment alpha all i get is a VERY dark texture.
lastly here is the code for drawing
static float a = 0;
if(a > 1.0)
a = 0.0;
else
a += 0.01f;
glUseProgramObjectARB(glslContext); //this is globally defined. could this pose a future problem?
glUniform1iARB(tex0, 0);
glUniform1iARB(tex1, 1);
glUniform1fARB(a, xrot);
sphere.DrawObj();
glUseProgramObjectARB(0);
thanks ahead of time!