PDA

View Full Version : How to check the error caused by shader linker?



SagoO
04-03-2011, 11:57 PM
programObject = glCreateProgramObjectARB();

// Create the fragment program
fragmentShader = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);
glShaderSourceARB(fragmentShader,1,&fragment_sourc e,NULL);
glCompileShaderARB(fragmentShader);
glGetObjectParameterivARB(programObject,GL_OBJECT_ COMPILE_STATUS_ARB,&CompileSuccess);
if (!CompileSuccess){
fprintf(stderr, "Compilation error\n");
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\n\n");
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?

Alfonse Reinheart
04-04-2011, 12:04 AM
You need to get the shader compile/linking logs. (http://www.opengl.org/wiki/GLSL_Object#Error_handling)

SagoO
04-04-2011, 02:14 AM
programObject = glCreateProgramObjectARB();

// Create the fragment program
fragmentShader = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);
glShaderSourceARB(fragmentShader,1,&fragment_sourc e,NULL);
glCompileShaderARB(fragmentShader);
glGetObjectParameterivARB(programObject,GL_OBJECT_ COMPILE_STATUS_ARB,&CompileSuccess);
if (!CompileSuccess){
fprintf(stderr, "Compilation error\n");
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\n",log);

if (!LinkSuccess){
fprintf(stderr, "Filter shader could not be linked\n\n");
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.

Alfonse Reinheart
04-04-2011, 03:23 AM
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.

SagoO
04-04-2011, 05:37 AM
Ops...I saw it. Thank... I had change the code as what you said:


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

glGetShaderInfoLog(fragmentShader,200,&length,log) ;

printf("Log file: ");
if(length>1)
printf("%s\n",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?

Alfonse Reinheart
04-04-2011, 07:13 AM
I don't know, but I'm guessing that it probably has something to do with the same problem you had here (http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Main=56823&Number=2947 19#Post294719) with non-ASCII characters.

SagoO
04-04-2011, 07:22 AM
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? :-(

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?

Alfonse Reinheart
04-04-2011, 07:25 AM
{"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.

SagoO
04-04-2011, 07:36 AM
Sorry...I just see the error. After modify, it still have the similar error like this:



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