Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [SOLVED] OSX - Failed to compile fragment shader  (Read 5302 times)

0 Members and 2 Guests are viewing this topic.

Max

  • Newbie
  • *
  • Posts: 10
    • View Profile
    • Email
[SOLVED] OSX - Failed to compile fragment shader
« 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/
and crosschecked with documentation on the GFX-card. 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" ?
« Last Edit: September 16, 2013, 08:36:23 pm by Max »

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: OSX - Failed to compile fragment shader
« Reply #1 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?
Back to C++ gamedev with SFML in May 2023

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: OSX - Failed to compile fragment shader
« Reply #2 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).
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Max

  • Newbie
  • *
  • Posts: 10
    • View Profile
    • Email
Re: OSX - Failed to compile fragment shader
« Reply #3 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.
« Last Edit: September 16, 2013, 08:37:06 pm by Max »

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: [SOLVED] OSX - Failed to compile fragment shader
« Reply #4 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
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: [SOLVED] OSX - Failed to compile fragment shader
« Reply #5 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
Back to C++ gamedev with SFML in May 2023