SFML community forums

Help => Graphics => Topic started by: Max on September 16, 2013, 03:55:58 pm

Title: [SOLVED] OSX - Failed to compile fragment shader
Post by: Max on September 16, 2013, 03:55:58 pm
I have bought the SFML book and downloaded the source code. Okay I had no problem compiling and linking this in linux and windows, and program runs okay there but on OSX 10.8 (Mountain Lion) it's another story. Used "clang++" to compile and link it. But when I am starting the program it runs ok until push play button.

It immediately crashes and this is what it prints in terminal:
Failed to compile fragment shader:
ERROR: 0:12: No matching function for call to clamp(float, int, int)


EXCEPTION: ResourceHolder::load - Failed to load /Users/max/Projects/EagleFighters/Game/Data/Shaders/Fullpass.vert
 

I suspect this is due to that my mac mini with NVIDIA GeForce 9400M isn't supporting latest GLSL.
Checked documentation on "clamp(...)" http://www.opengl.org/sdk/docs/manglsl/ (http://www.opengl.org/sdk/docs/manglsl/)
and crosschecked with documentation on the GFX-card. https://developer.apple.com/graphicsimaging/opengl/capabilities/ (https://developer.apple.com/graphicsimaging/opengl/capabilities/) but I am not really sure.

Anyone know exactly why this gives me "Failed to compile fragment shader" ?
Title: Re: OSX - Failed to compile fragment shader
Post by: FRex on September 16, 2013, 04:20:21 pm
Did you try to write own minimal shader to check if clamp exists on your glsl version?
Title: Re: OSX - Failed to compile fragment shader
Post by: Nexus on September 16, 2013, 04:35:09 pm
Try to add
#version 150
at the beginning of Brightness.frag in the subdirectory Media/Shaders of the chapter you're starting. Maybe also try other versions.

Otherwise, it would be possible to write a user-defined clamp() function:
float clamp(in float value, in float lower, in float upper)
{
    return max(min(value, upper), lower);
}
(alternatively using if, it depends on the implementation of min/max what's more efficient).
Title: Re: OSX - Failed to compile fragment shader
Post by: Max on September 16, 2013, 08:35:06 pm
Thanks guys!

I was your help able to find the problem and correct it. Shaders kinda new thing for me.
In Brightness.frag I found the error:
sourceFragment *= clamp(luminance - Threshold, 0, 1) * Factor;
 

Changed to this:
sourceFragment *= clamp(luminance - Threshold, 0.0, 1.0) * Factor;
 

Seems like clamp(...) didn't like "int" as parameters. It is a couple of weeks since I downloaded the source code, so I don't know if it has been fixed or not. Hope this might help other trying to get a OSX version to work.
Title: Re: [SOLVED] OSX - Failed to compile fragment shader
Post by: Nexus on September 16, 2013, 08:54:38 pm
This has indeed been fixed, a newer version is available on the GitHub repository:
https://github.com/SFML/SFML-Game-Development-Book
Title: Re: [SOLVED] OSX - Failed to compile fragment shader
Post by: FRex on September 16, 2013, 08:56:29 pm
Some implementations(ie. the one in my intel card) don't allow int literals to be used as float, I wanted to say that but I went through github and couldn't find it. :-X