Struct sfml::graphics::Shader [] [src]

pub struct Shader<'s> {
    // some fields omitted
}

Shader class (vertex and fragment)

Shaders are programs written using a specific language, executed directly by the graphics card and allowing to apply real-time operations to the rendered entities.

Methods

impl<'s> Shader<'s>
[src]

fn new_from_file(vertex_shader_filename: Option<&str>, fragment_shader_filename: Option<&str>) -> Option<Shader<'s>>

Load both the vertex and fragment shaders from files

This function can load both the vertex and the fragment shaders, or only one of them: pass None if you don't want to load either the vertex shader or the fragment shader. The sources must be text files containing valid shaders in GLSL language. GLSL is a C-like language dedicated to OpenGL shaders; you'll probably need to read a good documentation for it before writing your own shaders.

Arguments

  • vertexShaderFilename - Some(Path) of the vertex shader file to load, or None to skip this shader
  • fragmentShaderFilename - Some(Path) of the fragment shader file to load, or None to skip this shader

Return Some(Shader) or None

fn new_from_memory(vertex_shader: Option<&str>, fragment_shader: Option<&str>) -> Option<Shader<'s>>

Load both the vertex and fragment shaders from source codes in memory

This function can load both the vertex and the fragment shaders, or only one of them: pass None if you don't want to load either the vertex shader or the fragment shader. The sources must be valid shaders in GLSL language. GLSL is a C-like language dedicated to OpenGL shaders; you'll probably need to read a good documentation for it before writing your own shaders.

Arguments

  • vertexShader - Some(String) containing the source code of the vertex shader, or None to skip this shader
  • fragmentShader - Some(String) containing the source code of the fragment shader, or None to skip this shader

Return Some(Shader) or None

fn set_float_parameter(&mut self, name: &str, x: f32)

Change a f32 parameter of a shader

Arguments

  • name - Name of the parameter in the shader
  • x - Value to assign

fn set_float_2_parameter(&mut self, name: &str, x: f32, y: f32)

Change a 2-components vector parameter of a shader

name is the name of the variable to change in the shader. The corresponding parameter in the shader must be a 2x1 vector (vec2 GLSL type).

Arguments

  • name - Name of the parameter in the shader
  • x - First component of the value to assign
  • y - Second component of the value to assign

fn set_float_3_parameter(&mut self, name: &str, x: f32, y: f32, z: f32)

Change a 3-components vector parameter of a shader

name is the name of the variable to change in the shader. The corresponding parameter in the shader must be a 3x1 vector (vec3 GLSL type).

Arguments

  • name - Name of the parameter in the shader
  • x - First component of the value to assign
  • y - Second component of the value to assign
  • z - Third component of the value to assign

fn set_float_4_parameter(&mut self, name: &str, x: f32, y: f32, z: f32, w: f32)

Change a 4-components vector parameter of a shader

name is the name of the variable to change in the shader. The corresponding parameter in the shader must be a 4x1 vector (vec4 GLSL type).

Arguments

  • name - Name of the parameter in the shader
  • x - First component of the value to assign
  • y - Second component of the value to assign
  • z - Third component of the value to assign
  • w - Fourth component of the value to assign

fn set_texture_parameter(&mut self, name: &str, texture: &'s Texture)

Change a texture parameter of a shader

name is the name of the variable to change in the shader. The corresponding parameter in the shader must be a 2D texture (sampler2D GLSL type).

Arguments

  • name - Name of the texture in the shader
  • texture - Texture to assign

fn set_current_texture_parameter(&self, name: &str)

Change a texture parameter of a shader

This function maps a shader texture variable to the texture of the object being drawn, which cannot be known in advance. The corresponding parameter in the shader must be a 2D texture (sampler2D GLSL type).

Arguments

  • name - Name of the texture in the shader

fn bind(&mut self)

Bind a shader for rendering (activate it)

This function is not part of the graphics API, it mustn't be used when drawing SFML entities. It must be used only if you mix sfShader with OpenGL code.

fn is_available() -> bool

Tell whether or not the system supports shaders

This function should always be called before using the shader features. If it returns false, then any attempt to use sfShader will fail.

Return true if the system can use shaders, false otherwise

fn set_vector2_parameter(&mut self, name: &str, vector: &Vector2f)

Change a 2-components vector parameter of a shader

name is the name of the variable to change in the shader. The corresponding parameter in the shader must be a 2x1 vector (vec2 GLSL type).

Arguments

  • name - Name of the parameter in the shader
  • vector - Vector to assign

fn set_vector3_parameter(&mut self, name: &str, vector: &Vector3f)

Change a 3-components vector parameter of a shader

name is the name of the variable to change in the shader. The corresponding parameter in the shader must be a 2x1 vector (vec2 GLSL type).

Arguments

  • name - Name of the parameter in the shader
  • vector - Vector to assign

fn set_color_parameter(&mut self, name: &str, color: &Color)

Change a color parameter of a shader

name is the name of the variable to change in the shader. The corresponding parameter in the shader must be a 4x1 vector (vec4 GLSL type).

It is important to note that the components of the color are normalized before being passed to the shader. Therefore, they are converted from range [0 .. 255] to range [0 .. 1]. For example, a sf::Color(255, 125, 0, 255) will be transformed to a vec4(1.0, 0.5, 0.0, 1.0) in the shader.

Arguments

  • name - Name of the parameter in the shader
  • color - Color to assign

Trait Implementations

impl<'s> Drop for Shader<'s>
[src]

fn drop(&mut self)

Destroy an existing shader