glUseProgram = GL_INVALID_OPERATION

Started by
4 comments, last by TTT_Dutch 12 years, 10 months ago
Well, I am trying to create a shader class that is easy to use and easy to send values to. Now I am trying to test some of it and I get the error GL_INVALID_OPERATION right after I call glUseProgram. I can't figure out what is wrong but if someone could help, that would be great. Here is my code:


main.cpp: http://pastebin.com/w1JMzdqm
shader.cpp: http://pastebin.com/zuXe7Fut

Thanks ahead,
Brent
Advertisement
Are you sure that glUseProgram is actually the function causing the error? Errors flags are not reset until you check them, so it can be any function before glUseProgram, until the point where you last called glGetError to ensure that there are no errors flags left. Furthermore, you should check the documentation to see about what conditions causes that error flag to be set for the particular function. The specification states that glUseProgram can only cause an invalid operation under one condition, and you're not checking that condition.
While you're developing, it's useful to scatter glError calls around in your code all over the place for this reason -- although remember that calling glError while in some states is an error itself.

Personally I use a macro for this which takes a string context parameter, to make it simpler to find the command which triggers the error. It's a macro rather than a function so that later on I can simply define it to be null and strip out the glError calls. (Because glError acts like a glFlush reducing pipelining).
you aren't checking if the shaders compiled or link properly
http://opengl.org/wiki/Tutorial1:_Rendering_shapes_with_glDrawRangeElements,_VAO,_VBO,_shaders_%28C%2B%2B_/_freeGLUT%29
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
Ok I used to have Shaders loading right but now they are not compiling with these errors:
Vertex shader failed to compile with the following errors:
ERROR: 0:1: error(#76) Syntax error unexpected tokens following #version
ERROR: 0:1: error(#106) Version number not supported by GL2
ERROR: 0:1: error(#76) Syntax error unexpected tokens following #version
ERROR: error(#273) 3 compilation errors. No code generated

Fragment shader failed to compile with the following errors:
ERROR: 0:1: error(#76) Syntax error unexpected tokens following #version
ERROR: 0:1: error(#106) Version number not supported by GL2
ERROR: 0:1: error(#76) Syntax error unexpected tokens following #version
ERROR: error(#273) 3 compilation errors. No code generated


And both my shaders kinda look like this:
#version 330
....
main(void)
{
...
}

While you're developing, it's useful to scatter glError calls around in your code all over the place for this reason -- although remember that calling glError while in some states is an error itself.

Personally I use a macro for this which takes a string context parameter, to make it simpler to find the command which triggers the error. It's a macro rather than a function so that later on I can simply define it to be null and strip out the glError calls. (Because glError acts like a glFlush reducing pipelining).


Ok I did that and I still get the error when I try to use the program. Even thought all of the sudden my shaders aren't compiling.

This topic is closed to new replies.

Advertisement