问题描述
我试图添加灯光到我的当前场景的一个简单的多维数据集。在设置我的制服后,我从这个代码片段glGetError()得到一个1282错误
GLuint ambientHandle = glGetUniformLocation > 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);
这是我的着色器:
vertex.glsl
#version 120
属性vec4 coord3d;
attribute vec3 normal3d;
//将根据片段解释的输出值
changed 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
//来自顶点着色器的每个片段内插值
changed vec3 fN;
varying vec3 fL;
varying vec3 fE;
uniform vec4 ambientProduct,diffuseProduct,specular产品;
uniform mat4 mTransform;
uniform vec4 lightPosition;
uniform float shininess;
void main()
{
//标准化输入照明向量
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;
//如果光在顶点后面,抛弃镜面高亮
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;
}
产品和位置都是三个GLfloats的结构, 。我检查了所有的句柄值和我传递的值,他们都似乎有效。想法?
- 编辑:
我已经缩小到glUniform4fv调用。它发生在每一个之后。还有我双重检查程序 - > getHandle()指向看起来有效的东西。
我已经检查过program-> getHandle是一个有效的程序
以下是所有句柄的值:
程序句柄3
ambientHandle 0
diffuseHandle 1
specularHandle 5
lightPosHandle 2
shinyHandle 4
所以他们都看起来不错。为了测试,我注释掉了ambientProduct的下面的行。为了清楚起见,我明确使用这一行代替
glUniform4f(ambientHandle,ambientProd.x,ambientProd.y,ambientProd.z,ambientProd .w);
这些是执行行时ambientProd的值。
x = 0.200000003,y = 0.0,z = 0.200000003,w = 1.0
此项目的协作者移动了glUseProgram的调用。非常感谢您的帮助。
错误编号'1282`不是很描述。
glGetUniformLocation
的可能的错误代码是:
GL_INVALID_VALUE
GL_INVALID_OPERATION
其中没有固定值。尝试使用 gluErrorString()
获取错误字符串,或者查看 1282
地图的标题。
只是在黑暗中拍摄:
-
检查您的着色器是否已正确链接?
/ ul>
BTW:返回类型是GLint不是GLuint
着色器编译和链接没有错误 。
根据规范(请参阅:)
GL_INVALID_OPERATION
只应在以下情况下生成:
-
程式不是程式目标
其他问题:
-
您确定
程序
对象所属类的getHandle()
方法返回权利ID。我的意思是在成功链接中使用的那个。
你应该能够检查
glIsProgram(program-getHandle
返回GL_TRUE
strong> EDIT: Ah - 我错过了在您的示例中对
glUniform4fv
的调用。
类型
glGetUniformLocation
仍然GLint
,但我不认为这是问题。
根据规范(请参阅:)
GLUniformXX
产生GL_INVALID_OPERATION
束原因。对我来说,可能似乎适用的唯一一个是:
-
没有当前的程序对象
在尝试调用
glUniform()之前调用
glUseProgram(program-> getHandle())
code>?
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 programHere are the values of all handles:Program handle 3ambientHandle 0diffuseHandle 1specularHandle 5lightPosHandle 2shinyHandle 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.
解决方案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 those1282
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 yourprogram
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())
returnsGL_TRUE
EDIT: Ah - I missed those calls to
glUniform4fv
in your example.Correct return type for
glGetUniformLocation
is stillGLint
, but I don't think thats the problem.According to spec (see: http://www.opengl.org/sdk/docs/man/xhtml/glUniform.xml)
GLUniformXX
generatesGL_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 callingglUniform()
?
这篇关于OpenGL着色器错误1282的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
-