Game Development Reference
In-Depth Information
Loading shaders
The first step is making sure that the current GPU supports shaders. OpenGL introduced
shaders in its 2.0 version, so there are still graphics cards which do not support them
(however it's safe to assume the large majority do). To check if shaders can be used on the
current system we can use the static function Shader::isAvailable() :
The first step in using a shader is to load and compile it. SFML does the compiling part in-
ternally, so we only need to worry about supplying the shaders. Shaders can be loaded in
three ways—from a file, a string, or a stream. It uses the same format as other resources in
SFML. Here is how we create a shader program by loading the vertex and fragment
shaders:
Since SFML uses OpenGL, the shaders have to be written in OpenGL Shading Language
( GLSL ). Shader::load*() also tries to compile the shader. If any problems arise, an
error message appears in the console with the issue explained. the method also returns
false .
Another way of loading shaders is to store them directly in the code and load them as
strings:
Search WWH ::




Custom Search