How to update a single variable in GLSL

I am trying to update the position of the eyes in my shader from my application, but I always get error 1281 when I try to do this. I have no problem after initialization, only when I try to update the values. Here is my code:

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

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 is the function that I call to update the position of the eyes:

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 tried several ways to update the variable, and this is the last incarnation, thanks for watching, welcome all comments.

UPDATE: the error does not occur at all at all, my error is to assume that the error actually occurs when I draw a few spring:

for (int i = 0; i <2; i ++) {

  springs[i].Draw(); } 

When I draw the first, this is normal, but I get an error when calling the second at the point where glEnd () was called in response to glBegin (GL_LINE_STRIP). Sorry for the inconvenience, since this was not a mistake I posted, but at least if someone wants to know how to update single variables, then he is here.

+6
c ++ opengl glsl
source share
1 answer

Most likely, this is due to 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 will get a 1280 error (GL_INVALID_ENUM) if the mode is set to an invalid value. So 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 much depends on the exact error you get ...

+4
source share

All Articles