Toggling Shader Code

Hi all,

Sorry to post two consecutive posts, but I had two questions and didn’t want to cram everything into one big post.

I would like to be able to toggle on or off certain parts of the code in my vertex and fragment shaders based on a key press. My current setup is as follows. I have an int inside my main source file that has a value 0 or 1, and each corresponds to the code I want on or off. This value is passed off to a variable inside my shader, and I check in the main() of both my shaders to see what the value of this flag is.


//main source file

//declaring handler and int
GLint h_shadeMode;
int shadeMode = 0;

//in my function to install the shaders
h_shadeMode = safe_glGetUniformLocation(ShadeProg, "shadeMode");

//inside my draw function, setting a value
glUniform1f(h_shadeMode,shadeMode);

Later in that file I set the key presses that change the value of shadeMode, and I have a printf() to verify that it’s happening. In my shaders, I declare a

uniform int shadeMode;

which I assume has the value of shadeMode from my main source file. Inside the main of the VS, I do my calculations for the object position, light direction vector and gl_Position, then I have

if(shadeMode == 0)

inside of which are the shading calculations I want done if shadeMode is 0.

The fragment shader is just like the vertex shader. I have a

uniform int shadeMode;

which should be getting the value of shadeMode in the VS. Following that I have an if statement just like in the VS, where I only want it to do certain calculations if shadeMode is 1.

As you can guess, however, it’s not working. It looks like the VS is running, but not the FS?