elaverick's picture

How does uniform 3 work in OpenTK?

Hopefully quite a simple question, but how does GL.Uniform3 work in OpenTK? It's my first time venturing into GLSL and the program I'm working from as an example calls the following code:
shader.setUniformVariable3f("theColor", 1.0, 1.0, 0.0);

However OpenTK takes an int as the first variable rather than a variable name. Any clues?


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Radar's picture

Here, hope this helps to clear it up.
I overloaded the SendUniform so it's always the same name and not another name for each thing.
With the string you go get the id of that attribute and then send the data to that id

       // Searches for a specific uniform location and returns its id
       private int uniLoc(string ul)
        {
            int retval = -1;
            retval = GL.GetUniformLocation(this.programID, ul);
            return retval;
        }
        public void SendUniform(string uniformLocation, int value)
        {
            GL.Uniform1(this.uniLoc(uniformLocation), value);
        }
        public void SendUniform(string uniformLocation, float value)
        {
            GL.Uniform1(this.uniLoc(uniformLocation), value);
        }
        public void SendUniform(string uniformLocation, ref Vector2 value)
        {
            GL.Uniform2(this.uniLoc(uniformLocation), ref value);
        }
        public void SendUniform(string uniformLocation, ref Vector3 value)
        {
            GL.Uniform3(this.uniLoc(uniformLocation), ref value);
        }
... and so on for every thing you could send to the shader