Take the 2-minute tour ×

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);


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


        LoadCubeTexture(filename, compressedTexture);

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

        EyePos = glGetUniformLocation(program, "EyePosition");

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


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.

UPDATE: The error is not actually happening here at all, my fault for assuming it was, the error actually occurs when I draw a number of spring :




When I draw the first one it's fine but I get an error when calling the second at the point where call glEnd() in response to glBegin(GL_LINE_STRIP). Sorry for the inconvenience as it wasn't the error I posted but atleast if anyone wants to know how to update uniform variables then it's here.

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

It is most likely this is caused by the fact that EyePos is invalid.

What happens if you change the function to the following?

void GraphicsObject::UpdateEyePosition(Vector3d& eyePosition)
    EyePos = glGetUniformLocation(program, "EyePosition");
    glUniform4f(EyePos, eyePosition.X(),eyePosition.Y(), eyePosition.Z(), 1.0);

    DWORD bob = glGetError();

Edit: In response to your update the docs for glBegin/glEnd say that you'll get error 1280 (GL_INVALID_ENUM) if mode is set to an unacceptable value. Thus your problem is that GL_LINE_STRIP is not supported.

GL_INVALID_OPERATION is generated if glBegin is executed between a glBegin and the corresponding execution of glEnd.

GL_INVALID_OPERATION is generated if glEnd is executed without being preceded by a glBegin.

GL_INVALID_OPERATION is generated if a command other than glVertex, glColor, glSecondaryColor, glIndex, glNormal, glFogCoord, glTexCoord, glMultiTexCoord, glVertexAttrib, glEvalCoord, glEvalPoint, glArrayElement, glMaterial, glEdgeFlag, glCallList, or glCallLists is executed between the execution of glBegin and the corresponding execution glEnd.

GL_INVALID_OPERATION returns error 1282 and GL_INVALID_ENUM 1280 ... So a lot depends on what exact error you are getting ...

share|improve this answer
I still get an error, I was doing that to begin with. –  paj777 Mar 25 '10 at 9:44
What error do you get? And does the error come from the glGetUniformLocation or the glUniform4f? –  Goz Mar 25 '10 at 9:45
And what is EyePos value ? –  Bahbar Mar 25 '10 at 9:48
If I include glGetUniformLocation in the method then the error is there straight after the line but if I don't include that line and have EyePos as a private member the error still occurs. The error number is 1280 and that's all I know. And the value of EyePos is -1. –  paj777 Mar 25 '10 at 10:06
Well if glGetUniformLocation is failing then its likely your "program" value is wrong OR it is unable to find "EyePosition" in the program. Also note: 1280 is a different error and not one that glGetUniformLocation should return. If you get 1281 its because "program" is invalid. –  Goz Mar 25 '10 at 10:24
show 5 more comments

Your Answer


