Advertisement

"Beginning OpenGL Game Programming 2nd edition" fragment shader compile problems

Started by September 19, 2011 09:11 PM
2 comments, last by torelocks 13 years, 2 months ago
Hi guys, I'm hoping smeone can give me some advice.
I recently got "Beginning OpenGL Game Programming 2nd edition" by Luke Bernstead.

The first thing i have been doing is doing is reading through and compiling / running the projects.
When I get to the first one with a fragment shader (Chapter 6) however, it bombs out. After some debugging, I've narrowed it down to the fragment shader.

this is the supplied shader:

#version 130

in vec4 color;
out vec4 outColor;

void main(void) {
outColor = color;
}


I tried changing the shader to something like this, which allows the program to run but everything is rendered black:
void main()
{
gl_FragColor = gl_Color;
}

[as far as I can tell this is deprecated anyway]


I also mentioned the vert shader works; here it is:
#version 130

uniform mat4 projection_matrix;
uniform mat4 modelview_matrix;

in vec3 a_Vertex;
in vec3 a_Color;
out vec4 color;

void main(void)
{
vec4 pos = modelview_matrix * vec4(a_Vertex, 1.0);
gl_Position = projection_matrix * pos;
color = vec4(a_Color, 1.0);
}


When I investigate what glGetShaderInfoLog says, all i get is:
- Fragment Shader Fai[/quote]
useful, huh?


Unfortunately, I'm new to this whole thing and after a lot of searching on-line I'm still at an impasse. I hoping by posting here someone would be able to help me.

Oh yeah, my laptop's graphics card is: ATI Radeon HD 4500 series. I ran GPUCapsViewer; which told me that the card is fully shader version 1.3 compatible.

Any help appreciated, am i doing something wrong?!

Hi guys, I'm hoping smeone can give me some advice.
I recently got "Beginning OpenGL Game Programming 2nd edition" by Luke Bernstead.

The first thing i have been doing is doing is reading through and compiling / running the projects.
When I get to the first one with a fragment shader (Chapter 6) however, it bombs out. After some debugging, I've narrowed it down to the fragment shader.

this is the supplied shader:

#version 130

in vec4 color;
out vec4 outColor;

void main(void) {
outColor = color;
}


I tried changing the shader to something like this, which allows the program to run but everything is rendered black:
void main()
{
gl_FragColor = gl_Color;
}

[as far as I can tell this is deprecated anyway]


I also mentioned the vert shader works; here it is:
#version 130

uniform mat4 projection_matrix;
uniform mat4 modelview_matrix;

in vec3 a_Vertex;
in vec3 a_Color;
out vec4 color;

void main(void)
{
vec4 pos = modelview_matrix * vec4(a_Vertex, 1.0);
gl_Position = projection_matrix * pos;
color = vec4(a_Color, 1.0);
}


When I investigate what glGetShaderInfoLog says, all i get is:
- Fragment Shader Fai

useful, huh?


Unfortunately, I'm new to this whole thing and after a lot of searching on-line I'm still at an impasse. I hoping by posting here someone would be able to help me.

Oh yeah, my laptop's graphics card is: ATI Radeon HD 4500 series. I ran GPUCapsViewer; which told me that the card is fully shader version 1.3 compatible.

Any help appreciated, am i doing something wrong?!
[/quote]
If you are going to change the fragment shader, it needs to be compatible with the vertex shader. You have a varying variable called color from the vertex shader being passed to the fragment shader but where is it declared? You need to do this if you want to use the built-in type:
#version 130

in vec4 color;

void main(void) {
gl_FragColor = color;
}

Personally, when I am learning from a book with source code, I don't build the projects until I understand the underlying code. That way whether it compiles or not, I will be in a position to get it to work. The alternative is too frustrating.
Good judgment comes from experience; experience comes from bad judgment.
Advertisement
Hi torelocks,

Sorry you are having trouble with the source code that came with the book. Could you try the latest bug fix release from here: http://www.kazade.co.uk/downloads/boglgp/

Let me know if you still have trouble,

Thanks,

Luke.
Member of the NeHe team.
Hi guys,
firstly thanks for your quick replies.

@jesse, you make a very good point about understanding the content before compiling. This is what I'm trying to do, chapter by chapter but i was totally stumped with this one.
Thanks for pointing out that the output vertex variables need to be named the same as the input fragment ones...that was a detail I missed!

@Luke, much thanks for those bugfixes; the problem i was hitting is fixed. it was indeed one of the problems referred to in the fix notes:
* Since release, certain drivers (specifically AMD) started requiring precision qualifiers in the fragment shader causing the examples to fail while compiling the shader. All shaders are now fixed and an accompanying document gives a brief explanation of the issue.[/quote]

I did notice that one of the other bug-fixes is not fixed (as far as I can tell):
An incorrect size was passed to glGetShaderInfoLog causing any log output to be truncated. [/quote]


I'm guessing this is Luke Benstead...if so, thanks for writing a clear and readable book. One suggestion I would make is to place links to these bug-fixes on:
http://glbook.gamedev.net
as the book says that's the support web-site and there's currently no support available there.


Again, thanks for your help. It's great to see a friendly and helpful community. Hopefully i can give some back down the line :)

T

This topic is closed to new replies.

Advertisement