How to update a uniform variable in GLSL

Posted by paj777 on Stack Overflow See other posts from Stack Overflow or by paj777
Published on 2010-03-25T08:46:37Z Indexed on 2010/03/25 8:53 UTC
Read the original article Hit count: 779

Filed under:
|
|

Hi All,

I am trying to get update the eye position in my shader from my appliaction but I keep getting error 1281 when I attempt this. I have no problems after the initialization just when i subsequently try to update the values. Here is my code:

void GraphicsObject::SendShadersDDS(char vertFile [], char fragFile [], char filename []) {

            char *vs = NULL,*fs = NULL;

            vert = glCreateShader(GL_VERTEX_SHADER);
            frag = glCreateShader(GL_FRAGMENT_SHADER);

            vs = textFileRead(vertFile);
            fs = textFileRead(fragFile);
            const char * ff = fs;
            const char * vv = vs;

            glShaderSource(vert, 1, &vv, NULL);
            glShaderSource(frag, 1, &ff, NULL);

            free(vs); free(fs);

            glCompileShader(vert);
            glCompileShader(frag);

            program = glCreateProgram();
            glAttachShader(program, frag);
            glAttachShader(program, vert);

            glLinkProgram(program);
            glUseProgram(program);

        LoadCubeTexture(filename, compressedTexture);

        GLint location = glGetUniformLocation(program, "tex");
        glUniform1i(location, 0);
        glActiveTexture(GL_TEXTURE0);

        EyePos = glGetUniformLocation(program, "EyePosition");

        glUniform4f(EyePos, EyePosition.X(),EyePosition.Y(), 
                                    EyePosition.Z(), 1.0);          
        DWORD bob = glGetError();
        //All is fine here
        glEnable(GL_DEPTH_TEST);

}

And here's the function I call to update the eye position:

void GraphicsObject::UpdateEyePosition(Vector3d& eyePosition){

glUniform4f(EyePos, eyePosition.X(),eyePosition.Y(), 
                                    eyePosition.Z(), 1.0);

DWORD bob = glGetError();
//bob equals 1281 after this call       

}

I've tried a few ways now of updating the variable and this is the latest incarnation, thanks for viewing, all comments welcome.

© Stack Overflow or respective owner

Related posts about c++

Related posts about glsl