shader not working

Hello, I’ve just added a shader program to my scene:

vertex shader:


void main()
{		
	gl_Position = ftransform();
}

fragment shader:


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

I create the program like this:


void Shader_WriteInfo(GLhandleARB object)
{
	GLsizei len_log, written;
	glGetObjectParameterivARB(object,GL_OBJECT_INFO_LOG_LENGTH_ARB,&len_log);

	if(len_log>0)
	{
		GLcharARB* log=new GLcharARB[len_log+1];

		glGetInfoLogARB(object, len_log, &written, log);
		log[written]=0;
		WriteLog(log);

		delete[] log;
	}
}

DWORD filesize;
void* res;
GLcharARB* sourcecode=0;
ShaderProgram* sp=new ShaderProgram;

sp->vertex_shader=glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);
if(!sp->vertex_shader) goto shader_failure;
		
res=Resource_Load(vsh_filename,&filesize);
if(!res) goto shader_failure;

sourcecode=new GLcharARB[filesize+1];
memcpy(sourcecode,res,filesize);
sourcecode[filesize]=0;

Resource_Free(res);

glShaderSourceARB(sp->vertex_shader, 1, (const GLcharARB**)&sourcecode, NULL);
glCompileShaderARB(sp->vertex_shader);

delete[] sourcecode; sourcecode=0;

int param;
glGetObjectParameterivARB(sp->vertex_shader,GL_OBJECT_COMPILE_STATUS_ARB,&param);
if(param==GL_FALSE)
{
	WriteLog("Error compiling vertex shader %s:",vsh_filename);
	Shader_WriteInfo(sp->vertex_shader);
	goto shader_failure;
}
		sp->fragment_shader=glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);
if(!sp->fragment_shader) goto shader_failure;

res=Resource_Load(fsh_filename,&filesize);
if(!res) goto shader_failure;

sourcecode=new GLcharARB[filesize+1];
memcpy(sourcecode,res,filesize);
sourcecode[filesize]=0;

Resource_Free(res);

glShaderSourceARB(sp->fragment_shader, 1, (const GLcharARB**)&sourcecode, NULL);
glCompileShaderARB(sp->fragment_shader);

delete[] sourcecode; sourcecode=0;

int param;
glGetObjectParameterivARB(sp->fragment_shader,GL_OBJECT_COMPILE_STATUS_ARB,&param);
if(param==GL_FALSE)
{
	WriteLog("Error compiling fragment shader %s:",fsh_filename);
	Shader_WriteInfo(sp->fragment_shader);
	goto shader_failure;
}


sp->program=glCreateProgramObjectARB();
if(!sp->program) goto shader_failure;

glAttachObjectARB(sp->program,sp->vertex_shader);
glAttachObjectARB(sp->program,sp->fragment_shader); 
glLinkProgramARB(sp->program);

int param;
glGetObjectParameterivARB(sp->program,GL_OBJECT_LINK_STATUS_ARB,&param);
if(param==GL_FALSE)
{
	WriteLog("Error linking program on vertex shader %s and fragment shader %s:",vsh_filename,fsh_filename);
	Shader_WriteInfo(sp->program);
	goto shader_failure;
}


shader_failure:
delete[] sourcecode;
sp->Free();
delete sp;

return 0;

I selected my shader program with “glUseProgramObjectARB”. (I call it every frame.) In theory, everything in my scene should turn red. But it doesn’t, my scene looks exactly the same as before I used the shader program.

I’ve checked the info logs, there are no compiler errors and linking goes fine as well.

Does anyone else know what could be causing this malfunction?

Have you tried checking OpenGL error code after each GL call - glGetError() function? I suggest you to use GLIntercept to do error checking automatically.

That “glGetError” function returns GL_INVALID_VALUE right after the call to “glUseProgramObjectARB”.


glUseProgramObjectARB(sp->program);
glGetError();

I believe I got it now. My application uses a pbuffer. It appears that this shader was linked at the moment the pbuffer was the active rendering context. So the onscreen buffer didn’t know about the shader.

So shaders are linked to rendering contexts. I didn’t know that.

Every resource (textures, shaders, display lists, various buffers) are tied to OpenGL context. If you need to share them then you need to specify it manually. On Windows it is done with wglShareLists function.