OpenGL shader not loading (beginner)

Hi All, I´m just starting with shaders,…so sorry for this ‘easy’ question.

I just want to test following shader:

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

I do it like following:

in a constructor of my class I:

  • glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB)
  • load the source of the shader
  • load the shader to handle: glShaderSourceARB
  • compile it: glCompileShaderARB
  • get info: glGetInfoLogARB
    // until now everything returns 0 (no error)

then in initializeGL I:

  • create a program object glCreateProgramObjectARB();
  • attach the shader glAttachObjectARB(prg, shader_vtx->handle_);
    // here I’m getting glError - 1281[/b]
  • link the program: glLinkProgramARB(prg);

then in paintGL loop I:

  • glUseProgramObjectARB(prg); // here I’m not 100% sure where to place it. I’m creating a VBO(drawElements, TRIANGLE_STRIP). But if I place it anywhere nothing changes (I’m getting still my old color) - shader should change it to green.

thank you in advance,…

I guess, you have to have a vertex shader attached before linking, not just a fragment one (though, you can have only a vertex shader).

Is there a current opengl context when your “class I” constructor is called?
You need a current opengl context before you can use GL commands.
BTW, you don’t need a vertex shader attached at all. It will use the default vertex shader (i.e. the fixed function vertex shader) if linked without a custom one attached. Same goes for a fragment shader…default gets used if none attached at link stage.