Cannot retrieve location of uniform variable in my vertex shader

I made a wrapper class for shaders in Java and added following method to set value to floating uniform variables in my vertex shader program:


    public boolean setUniformVariable( String name, float var )
    {
        int var_location = gl.glGetUniformLocation( program, name );
        if( var_location == -1 ) return false;
        gl.glUniform1f( var_location, var );
        return true;
    }

Everything else in my class works. That is I can compile shaders, bind them to int program and use them in the rest of my application.

In the vertex program i declare uniform float time; at the top, and then try to set a value to it on display call. but this function (setUniformVariable) always returns false, meaning that glGetUniformLocation is not finding the variable.

What is going on here?

shameless bump because I am really lost on this, and cannot for the life of me figure out why I cannot get handles on my uniform variables in my shaders.

Hello I had a problem similar to this once. I was reading the shader into memory incorrectly but they were compiling correctly. it took me forever to find. Maybe the same thing is happening to you? just an idea…

[Edit] … come to think of it, It might have been that the program i was writing them with was storing bad characters… I can’t remember. I’m at work when i get home i’ll post some code and a shader that i know works.

you mean that the variable name is not what im expecting it to be because of the way I am reading in the file?

Is there a way to retrieve a list of variables from a shader and print them out?

I resolved the issue. I wasn’t using the variable time in my shader, just declared it, so I guess it got "optimized out’. It finds the variable just fine now that i actually use it :slight_smile: