How to check the error caused by shader linker?


programObject = glCreateProgramObjectARB();

	// Create the fragment program
  	fragmentShader = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);
  	glShaderSourceARB(fragmentShader,1,&fragment_source,NULL);
  	glCompileShaderARB(fragmentShader);
	glGetObjectParameterivARB(programObject,GL_OBJECT_COMPILE_STATUS_ARB,&CompileSuccess);
	if (!CompileSuccess){
    		fprintf(stderr, "Compilation error
");
    	exit(1);
  	}
  	glAttachObjectARB(programObject,fragmentShader);

  	// Link the shader into a complete GLSL program.
  	glLinkProgramARB(programObject);	
  	glGetObjectParameterivARB(programObject,GL_OBJECT_LINK_STATUS_ARB,&LinkSuccess);
  	if (!LinkSuccess){
    		fprintf(stderr, "Filter shader could not be linked

");
    	exit(1);
  	}

Well. When I run my program, I receive the message “Filter shader could not be linked”. How to check what is the error over there?

You need to get the shader compile/linking logs.


programObject = glCreateProgramObjectARB();

	// Create the fragment program
  	fragmentShader = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);
  	glShaderSourceARB(fragmentShader,1,&fragment_source,NULL);
  	glCompileShaderARB(fragmentShader);
	glGetObjectParameterivARB(programObject,GL_OBJECT_COMPILE_STATUS_ARB,&CompileSuccess);
	if (!CompileSuccess){
    		fprintf(stderr, "Compilation error
");
    		exit(1);
  	}
  	glAttachObjectARB(programObject,fragmentShader);

  	// Link the shader into a complete GLSL program.
  	glLinkProgramARB(programObject);	
  	glGetObjectParameterivARB(programObject,GL_OBJECT_LINK_STATUS_ARB,&LinkSuccess);

	int b,length;
	char log[length];
		
	glGetShaderInfoLog(fragmentShader,200,&length,log);

	printf("Log file: ");
	if(length>1)
		printf("%s
",log);

  	if (!LinkSuccess){
    		fprintf(stderr, "Filter shader could not be linked

");
    		exit(1);
  	}

Well. I am not sure that the method i use that function correct or not. It returns me segmentation fault once I call the glGetShaderInfoLog() function.

int b,length;
char log[length];

I don’t see how that compiles. Even under C99 rules, where stack arrays can be “dynamic,” that might compile, but it certainly won’t execute. ‘length’ needs to have a value before you try to use it to size an array. Or, more likely, you intend the ‘log’ array to have 200 elements.

In general, you should call glGetShader with GL_INFO_LOG_LENGTH to get the size of the infolog. Then create a buffer to store the log and call glGetShaderInfoLog.

Also, you might want to reconsider mixing the ARB_shader_objects functions and objects with the core GL object functionality. That is, if you’re using glCreateShaderARB, then every function you use that object with needs to have an ARB suffix. It’s all or nothing; either you’re using ARB_shader_objects (for some reason), or you’re using the core GL version. Don’t mix them. Especially since ARB_shader_objects returns an opaque handle, rather than a 32-bit integer.

Ops…I saw it. Thank… I had change the code as what you said:


GLint b;
	GLint length;
	glGetShaderiv(fragmentShader,GL_INFO_LOG_LENGTH,&length);
	unsigned char* log = (unsigned char*)malloc(length);
		
	glGetShaderInfoLog(fragmentShader,200,&length,log);

	printf("Log file: ");
	if(length>1)
		printf("%s
",log);


I assume it correct since it can print out the log file. Is it correct?

The log file I get is:

Log file: Error: 2005: ‘)’ expected but ‘???’ found.

What does it means?

I don’t know, but I’m guessing that it probably has something to do with the same problem you had here with non-ASCII characters.

Okay. I assume is that issue cause this error happens. Last time I modified the code become like this:


static const char *tex = "texture";
.
.
.
// Get location of the sampler uniform
location = glGetUniformLocationARB(programObject, tex);

Anyway to solve this problem? Why other example can directly pass string into the function but mine cannot? :frowning:

Even it can compile, I not sure it works or not. Do you think I pass the string like this way will cause that error?

{“texture”};

That’s not a string; that is an array (of length 1) of strings. That has the type “const char **”. If that works at all, it’s only because you got lucky.

Are you new to C/C++? If so, you may want to get some more programming experience before you start trying to deal with graphics work.

Sorry…I just see the error. After modify, it still have the similar error like this:


Log file: Error: 2005: ')' expected but '=' found.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.