OpenGL Shader error 1282
Asked Answered
M

3

19

I am trying to add lighting to my current scene of a simple cube. After setting up my uniforms I get a 1282 error from glGetError() for this piece of code

GLuint ambientHandle = glGetUniformLocation(program->getHandle(), "ambientProduct");
glUniform4fv( ambientHandle, 1, ambientProduct );
GLuint diffuseHandle = glGetUniformLocation(program->getHandle(), "diffuseProduct");
glUniform4fv( diffuseHandle, 1, diffuseProduct );
GLuint specularHandle = glGetUniformLocation(program->getHandle(), "specularProduct");
glUniform4fv( specularHandle, 1, specularProduct );
GLuint lightPosHandle = glGetUniformLocation(program->getHandle(), "lightPosition");
glUniform4fv( lightPosHandle, 1, light.position );
GLuint shinyHandle = glGetUniformLocation(program->getHandle(), "shininess");
glUniform1f( shinyHandle, materialShininess );

Here are my shaders: vertex.glsl

#version 120

attribute vec4 coord3d;
attribute vec3 normal3d;

// output values that will be interpretated per-fragment
varying  vec3 fN;
varying  vec3 fE;
varying  vec3 fL;

uniform vec4 lightPosition;
uniform mat4 mTransform;

void main()
{
    fN = normal3d;
    fE = coord3d.xyz;
    fL = lightPosition.xyz;

    if( lightPosition.w != 0.0 ) {
    fL = lightPosition.xyz - coord3d.xyz;
    }

    gl_Position = mTransform*coord3d;
}

fragment.glsl

// per-fragment interpolated values from the vertex shader
varying  vec3 fN;
varying  vec3 fL;
varying  vec3 fE;

uniform vec4 ambientProduct, diffuseProduct, specularProduct;
uniform mat4 mTransform;
uniform vec4 lightPosition;
uniform float shininess;

void main() 
{ 
    // Normalize the input lighting vectors
    vec3 N = normalize(fN);
    vec3 E = normalize(fE);
    vec3 L = normalize(fL);

    vec3 H = normalize( L + E );

    vec4 ambient = ambientProduct;

    float Kd = max(dot(L, N), 0.0);
    vec4 diffuse = Kd*diffuseProduct;

    float Ks = pow(max(dot(N, H), 0.0), shininess);
    vec4 specular = Ks*specularProduct;

    // discard the specular highlight if the light's behind the vertex
    if( dot(L, N) < 0.0 ) {
    specular = vec4(0.0, 0.0, 0.0, 1.0);
    }

    gl_FragColor = ambient + diffuse + specular;
    gl_FragColor.a = 1.0;
} 

The products and position are each a struct of three GLfloats and shininess is a float. I have checked all of the values of the handles and the values I am passing and they all seem valid. Ideas?

--EDIT: I have narrowed it to the glUniform4fv calls. It happens after each one. Also I have double checked that the program->getHandle() is pointing to something that looks valid.

I have checked program->getHandle is a valid program Here are the values of all handles: Program handle 3 ambientHandle 0 diffuseHandle 1 specularHandle 5 lightPosHandle 2 shinyHandle 4

So they all look good. For testing I am commenting out the lines below the ones for ambientProduct. For clarity I am explicitly using this line instead

glUniform4f( ambientHandle, ambientProd.x, ambientProd.y, ambientProd.z, ambientProd.w );

These are the values for ambientProd at the time that line is executed. x = 0.200000003, y = 0.0, z = 0.200000003, w = 1.0

A collaborator on this project moved the call for glUseProgram. Thanks for the help folks.

Macedo answered 30/3, 2013 at 19:48 Comment(0)
I
24

Error number ´1282` is not very descriptive.

Possible error codes for glGetUniformLocation are:

GL_INVALID_VALUE
GL_INVALID_OPERATION

Which don't have a fixed value. Try to get the error string with gluErrorString() or take a look in the header to which of those 1282 maps.

Just a shot in the dark: but did you ...

  • check your shader got compiled without error?

  • check your shader got linked without error?

BTW: return type is GLint not GLuint

"Shaders compiled and linked without error" Hmm, this looks odd.

According to spec (see: http://www.opengl.org/sdk/docs/man/xhtml/glGetUniformLocation.xml) GL_INVALID_OPERATION should only be generated if:

  • program is not a program objec

  • program has not been successfully linked

Other question:

  • are you sure the getHandle()method of the class your program Object belongs to returns the right id. I mean the one that was used in the sucessfully linking.

    you should be able to verify with checking if glIsProgram(program-getHandle()) returns GL_TRUE

EDIT: Ah - I missed those calls to glUniform4fv in your example.

Correct return type for glGetUniformLocation is still GLint, but I don't think thats the problem.

According to spec (see: http://www.opengl.org/sdk/docs/man/xhtml/glUniform.xml) GLUniformXX generates GL_INVALID_OPERATION for a whole bunch of reasons. To me the only one that possibly seems to apply is:

  • there is no current program object

    Did you call glUseProgram (program->getHandle()) prior to trying to calling glUniform()?

Interpretation answered 30/3, 2013 at 20:3 Comment(3)
Shaders compiled and linked without error and it is the GL_INVALID_OPERATION errorMacedo
I missed the call to glUniform() in your example - there's a wohle bunch of reasons listed in the spec. IMHO the program not being the active one seeming the only one that possibly applies.Interpretation
Wow, I really forgot to call glUseProgram. Tnx.Pricket
T
2

I had a similar issue where I was going from GL3.3 to GLES and had the issue that for glTexImage2D calls, the output format must be the same as the internal format.

So I had to change:

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);

to

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);.

I remember reading it somewhere but completely forgot, so I will just leave this here just in case it helps someone.

Theogony answered 4/7, 2023 at 7:51 Comment(0)
S
1

Generally this error number occurs when you are using a different programID from the programID generated by openGL at the time of creating the shader. It means that you are using a different programID at the time of binding vertexShader or fragmentShader or whatever other shader you are using.

Santasantacruz answered 25/3, 2019 at 10:30 Comment(1)
I have made a few minor changes to your answer. Please check that my changes are correct and that I have not added any mistakes. You can edit the answer further if necessary.Vernavernacular

© 2022 - 2024 — McMap. All rights reserved.