🔒 Locked
GLSL Problem
Advertisement
Original Post
Hi, I'm doing some stuff using GLSL, and I'm facing some problems. First, when I first tried to compile a simple fragment sahder, one that only outputs a constant color: void main() { gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0); } the compiler raised an error on the identifier void. But if I insert a blank line before the void main() line, it compiles OK. Well, that's annoying, but I could solve it. Now, I add this compiled shader to a program, and try to link it. The linker then rises an error saying that "Not all shaders have valid object code". There's no place I have found where I can check what this quite ambiguous message means, and I guess it's driver/vendor specific. I'm using an ATI Radeon 9800 SE with latest Catalyst 4.10 drivers. OpenGL version, as returned by glGetString, is 1.5.4650 WinXP Release, and GLSL version is 1.00. Anyone has any clue why this may be happening? May this be because I'm not adding a vertex shader to the program? If I have understood documentation, there's no need for a program to contain both vertex and fragment shaders, defaulting to fixed functionality for absent shaders. One last clue: this same behaviour happens if I rename the main function with another name: shader compiles OK, but program fails to link with the same error message. But this makes sense, because fragment shader has no entry point. Thank you all.
Well here are some pointers:
1) Yes you need a vertex shader to translate your vertices. for example:
void main(void)
{
gl_Position = ftransform();
}
This should do the job just fine!
2) In your fragment program you are forgeting the void:
void main(void)
{
...
}
Maybe void will fix the problem.
Let me know if that works.
BTW you can always use RenderMonkey or Shader Designer to test your shaders.
1) Yes you need a vertex shader to translate your vertices. for example:
void main(void)
{
gl_Position = ftransform();
}
This should do the job just fine!
2) In your fragment program you are forgeting the void:
void main(void)
{
...
}
Maybe void will fix the problem.
Let me know if that works.
BTW you can always use RenderMonkey or Shader Designer to test your shaders.
>>Anyone has any clue why this may be happening? May this be because I'm not adding a vertex shader to the program? If I have understood documentation, there's no need for a program to contain both vertex and fragment shaders, defaulting to fixed functionality for absent shaders.<<
as blackbox saiz u need a vertex shader,
from the spec u can
vertex program + NO fragment program == OK
vertex program + fragment program == OK
no vertex program + fragment program == NOT OK
as blackbox saiz u need a vertex shader,
from the spec u can
vertex program + NO fragment program == OK
vertex program + fragment program == OK
no vertex program + fragment program == NOT OK
OK, I found out what was going wrong.
I was passing each line of the source as a separate string. Now I have passed the whole source in one string and it has worked.
Oh, and yes, it is possible to have a fragment shader without a vertex shader.
But now my question is: why the glSetShaderSoureARB function takes several strings as input?
Thank you all!
I was passing each line of the source as a separate string. Now I have passed the whole source in one string and it has worked.
Oh, and yes, it is possible to have a fragment shader without a vertex shader.
But now my question is: why the glSetShaderSoureARB function takes several strings as input?
Thank you all!
the functions takes several strings as input, so you can create 'generic' functions (eg for lighting) and 'link' the one you want.
You could create a fragment shader which calls a 'lightme' function to return the color of the fragment due to lighting only. You could then create two files, one in which 'lighme' calculates the color with only a single light and the other in which 'lightme' can handle 4 lights. Then during compilation you can 'link' the file you want, without needing to change the rest of the fragment shader file.
You could create a fragment shader which calls a 'lightme' function to return the color of the fragment due to lighting only. You could then create two files, one in which 'lighme' calculates the color with only a single light and the other in which 'lightme' can handle 4 lights. Then during compilation you can 'link' the file you want, without needing to change the rest of the fragment shader file.
Yeah, rigth, that makes sense.
But, isn't it more elegant to create a shader object for every shader file, add all of them to the program and link them together to achieve the same result?
I personally prefer this approach of a one-to-one relationship between shader files and shader objects, but I guess other people may prefer the first.
But, isn't it more elegant to create a shader object for every shader file, add all of them to the program and link them together to achieve the same result?
I personally prefer this approach of a one-to-one relationship between shader files and shader objects, but I guess other people may prefer the first.
Well maybe, but remember that those 'helper' files do nothing by themselves. There is no main function, thus shaderobjects can not be created from them alone.
I just think of it as a kind of #include mechanism.
I just think of it as a kind of #include mechanism.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement