OpenGL Shader Error 1282

I am trying to add lighting to my current simple cube scene. After setting up my uniform, I get error 1282 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 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; } 

Products and position represent a structure of three GLfloats, and gloss is a float. I checked all the descriptor values ​​and the values ​​that I pass, and they all seem valid. Ideas?

- EDIT: I narrowed it down to glUniform4fv calls. This happens after each. I also double checked that the program-> getHandle () indicates that it looks valid.

I checked the program-> getHandle - a valid program Here are the values ​​of all the descriptors: Program control 3 ambientHandle 0 diffuseHandle 1 specularHandle 5 lightPosHandle 2 shinyHandle 4

So they all look good. For testing, I comment on the lines below for ambientProduct. For clarity, I explicitly use this line instead

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

These are the values ​​for ambientProd at runtime of this line. x = 0.200000003, y = 0.0, z = 0.200000003, w = 1.0

The project employee has moved the glUseProgram call. Thanks for helping people.

+7
source share
1 answer

Error number '1282` is not very descriptive.

Possible error codes for glGetUniformLocation :

 GL_INVALID_VALUE GL_INVALID_OPERATION 

Which do not have a fixed value. Try to get a string with the error gluErrorString() or look in the header to which of these 1282 cards.

Just in the dark: but you ...

  • check that your shader compiled without errors?

  • to check that your shader is connected without errors?

BTW: return type - GLint not GLuint

"Shaders compiled and linked without errors." Hmm, that looks weird.

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

  • the program is not an objec program

  • the program was not successfully connected

Another question:

  • Are you sure that the getHandle() method of the class your program Object belongs to returns the correct identifier. I mean the one that was used for successful binding.

    you should check if glIsProgram(program-getHandle()) GL_TRUE

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

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

According to the specification (see http://www.opengl.org/sdk/docs/man/xhtml/glUniform.xml ) GLUniformXX generates GL_INVALID_OPERATION for a number of reasons. For me, the only thing that may seem to be applicable:

  • missing current program object

    Did you call glUseProgram (program->getHandle()) before you tried to call glUniform() ?

+10
source

All Articles