Loading and Using Fragment Shader

Hello, hope this is the place for the question.

Basically im trying to load a fragment shader into openGL and apply it to a mesh…

Shader Code:


void main()
	{
	gl_FragColor = vec4(0.4,0.4,0.8,1.0);
	}

Loading Shader: (I’ve put a cout<<glGetError<<endl; after each line and they all seem to succeed)


const char *shaderArray = &file_string;
shader = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource( shader, 1, &shaderArray, NULL );
glCompileShader( shader );
program = glCreateProgram();
glAttachShader( program, shader );
glLinkProgram( program );

Then after the glUseProgram a GL_INVALID_OPERATION is generated…


if( glIsProgram( program ) )
{
glUseProgram( program );
cout<<"Error Code: "<<glGetError()<<endl;
}

I’m assuming its due to:
“GL_INVALID_OPERATION is generated if program could not be made part of current state.”
OpenGL Reference Manual

But I can’t see why this is - the use Program is called once GL is initiated and everything…

I’m sure its some silly mistake, but any help would be greatly appreciated.

Thanks in Advance

  • Jorj

you should check if shader got compiled and linked correct. the first for sure. query the compile and link strings for errors or warning. i forgot the exact code though. google.

If you do not know this tutorial already, I suggest you to check out the Lighthouse3D GLSL tutorial. It is a good tutorial to start with glsl and you will find how to handle errors.

Awesome, there was an error, it was in loading the string into openGL, and converting char array to “const char **”'s…

Thanks for your help

  • Jorj