# glUseProgram = GL_INVALID_OPERATION

This topic is 2446 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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

Brent

##### Share on other sites
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.

##### Share on other sites
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).

##### Share on other sites
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)
{
...
}

##### Share on other sites

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.