class
#include <include/redhand/shader.hpp>
shader This class provides a simple abstraction for opengl shaders.
Contents
To render anything on a screen a shader is needed to transform the supplied data into actual pixels that you will see on the screen.
Constructors, destructors, conversion operators
Public functions
- auto createShaderFromFile(std::string_view vertexPath, std::string_view fragmentPath) -> int
- Create a Shader From a file.
- auto createShaderFromCode(std::string_view vertexSource, std::string_view fragmentSource) -> int
- Create a Shader From source Code.
- auto createDefaultShader() -> int
- Initilizes the shader object with the default shader.
- auto hasErrored() -> bool
- This function returns true if an error happend during the setup of the shader or the shader is not initilized.
- void use()
- This function activates the shader and sets the camera position.
- auto getName() -> std::string_view
- This function return the name the shader has.
- auto getID() -> unsigned int
- This function returns the ID of the shader for the use in some OpenGL functions.
- void setBool(const std::string& name, bool value) const
- The setBool functions set a uniform vector of the shader to given values.
- void setBool(const std::string& name, bool value, bool value2) const
- The setBool functions set a uniform vector of the shader to given values.
- void setBool(const std::string& name, bool value, bool value2, bool value3) const
- The setBool functions set a uniform vector of the shader to given values.
- void setBool(const std::string& name, bool value, bool value2, bool value3, bool value4) const
- The setBool functions set a uniform vector of the shader to given values.
- void setInt(const std::string& name, int value) const
- The setInt functions set a uniform vector of the shader to given values.
- void setInt(const std::string& name, int value, int value2) const
- The setInt functions set a uniform vector of the shader to given values.
- void setInt(const std::string& name, int value, int value2, int value3) const
- The setInt functions set a uniform vector of the shader to given values.
- void setInt(const std::string& name, int value, int value2, int value3, int value4) const
- The setInt functions set a uniform vector of the shader to given values.
- void setFloat(const std::string& name, float value) const
- The setFloat functions set a uniform vector of the shader to given values.
- void setFloat(const std::string& name, float value, float value2) const
- The setFloat functions set a uniform vector of the shader to given values.
- void setFloat(const std::string& name, float value, float value2, float value3) const
- The setFloat functions set a uniform vector of the shader to given values.
- void setFloat(const std::string& name, float value, float value2, float value3, float value4) const
- The setFloat functions set a uniform vector of the shader to given values.
- void getFloat(const std::string& name, float dest[]) const
- This function gets a uniform float from an uniform vector and saves it to the destination.
- void setCamera(float pos_x, float pos_y)
- This function is used to set the position of the camera.
- void moveCamera(float delta_pos_x, float delta_pos_y)
- This function is used to set the position of the camera.
- void setProjectionmatrix(glm::mat4 projection)
- This function sets the projection matrix of the shader to the given matrix.
- void setTextureScale(glm::vec2 scale)
- This function sets the texture scale of the shader to the given vector.
Function documentation
redhand:: shader:: shader(std::string_view name)
This constructor creates a shader with a given name.
Parameters | |
---|---|
name | The name of the Shader |
The default vertex and fragment shaders from the shaderSource.hpp will be used.
int redhand:: shader:: createShaderFromFile(std::string_view vertexPath,
std::string_view fragmentPath)
Create a Shader From a file.
Parameters | |
---|---|
vertexPath | The location of the vertex Shader |
fragmentPath | The location of the Fragment Shader |
Returns | int negative if something went wrong |
int redhand:: shader:: createShaderFromCode(std::string_view vertexSource,
std::string_view fragmentSource)
Create a Shader From source Code.
Parameters | |
---|---|
vertexSource | The source code of the vertex shader |
fragmentSource | The source code of the fragment shader |
Returns | int |
int redhand:: shader:: createDefaultShader()
Initilizes the shader object with the default shader.
Returns | int negative value if anything went wrong |
---|
std::string_view redhand:: shader:: getName()
This function return the name the shader has.
It will be "shader" if nothing else was specified.
void redhand:: shader:: setBool(const std::string& name,
bool value) const
The setBool functions set a uniform vector of the shader to given values.
Parameters | |
---|---|
name | The name of the uniform variable |
value | The x component of the Vector |
void redhand:: shader:: setBool(const std::string& name,
bool value,
bool value2) const
The setBool functions set a uniform vector of the shader to given values.
Parameters | |
---|---|
name | The name of the uniform variable |
value | The x component of the Vector |
value2 | The y component of the Vector |
void redhand:: shader:: setBool(const std::string& name,
bool value,
bool value2,
bool value3) const
The setBool functions set a uniform vector of the shader to given values.
Parameters | |
---|---|
name | The name of the uniform variable |
value | The x component of the Vector |
value2 | The y component of the Vector |
value3 | The z component of the Vector |
void redhand:: shader:: setBool(const std::string& name,
bool value,
bool value2,
bool value3,
bool value4) const
The setBool functions set a uniform vector of the shader to given values.
Parameters | |
---|---|
name | The name of the uniform variable |
value | The x component of the Vector |
value2 | The y component of the Vector |
value3 | The z component of the Vector |
value4 | The w component of the Vector |
void redhand:: shader:: setInt(const std::string& name,
int value) const
The setInt functions set a uniform vector of the shader to given values.
Parameters | |
---|---|
name | The name of the uniform variable |
value | The x component of the Vector |
void redhand:: shader:: setInt(const std::string& name,
int value,
int value2) const
The setInt functions set a uniform vector of the shader to given values.
Parameters | |
---|---|
name | The name of the uniform variable |
value | The x component of the Vector |
value2 | The y component of the Vector |
void redhand:: shader:: setInt(const std::string& name,
int value,
int value2,
int value3) const
The setInt functions set a uniform vector of the shader to given values.
Parameters | |
---|---|
name | The name of the uniform variable |
value | The x component of the Vector |
value2 | The y component of the Vector |
value3 | The z component of the Vector |
void redhand:: shader:: setInt(const std::string& name,
int value,
int value2,
int value3,
int value4) const
The setInt functions set a uniform vector of the shader to given values.
Parameters | |
---|---|
name | The name of the uniform variable |
value | The x component of the Vector |
value2 | The y component of the Vector |
value3 | The z component of the Vector |
value4 | The w component of the Vector |
void redhand:: shader:: setFloat(const std::string& name,
float value) const
The setFloat functions set a uniform vector of the shader to given values.
Parameters | |
---|---|
name | The name of the uniform variable |
value | The x component of the Vector |
void redhand:: shader:: setFloat(const std::string& name,
float value,
float value2) const
The setFloat functions set a uniform vector of the shader to given values.
Parameters | |
---|---|
name | The name of the uniform variable |
value | The x component of the Vector |
value2 | The y component of the Vector |
void redhand:: shader:: setFloat(const std::string& name,
float value,
float value2,
float value3) const
The setFloat functions set a uniform vector of the shader to given values.
Parameters | |
---|---|
name | The name of the uniform variable |
value | The x component of the Vector |
value2 | The y component of the Vector |
value3 | The z component of the Vector |
void redhand:: shader:: setFloat(const std::string& name,
float value,
float value2,
float value3,
float value4) const
The setFloat functions set a uniform vector of the shader to given values.
Parameters | |
---|---|
name | The name of the uniform variable |
value | The x component of the Vector |
value2 | The y component of the Vector |
value3 | The z component of the Vector |
value4 | The w component of the Vector |
void redhand:: shader:: getFloat(const std::string& name,
float dest[]) const
This function gets a uniform float from an uniform vector and saves it to the destination.
Parameters | |
---|---|
name | The name of the uniform variable |
dest | The array where the contents of the variables will be saved to |
void redhand:: shader:: setCamera(float pos_x,
float pos_y)
This function is used to set the position of the camera.
Parameters | |
---|---|
pos_x | The x coordinate of the camera |
pos_y | The y coordinate of the camera |
All units are in world space cooridinates.
void redhand:: shader:: moveCamera(float delta_pos_x,
float delta_pos_y)
This function is used to set the position of the camera.
Parameters | |
---|---|
delta_pos_x | The amount the camera should move along the x-Axis |
delta_pos_y | The amount the camera should move along the y-Axis |
All units are in world space cooridinates
void redhand:: shader:: setProjectionmatrix(glm::mat4 projection)
This function sets the projection matrix of the shader to the given matrix.
Parameters | |
---|---|
projection | the projection matrix which should be used |
void redhand:: shader:: setTextureScale(glm::vec2 scale)
This function sets the texture scale of the shader to the given vector.
Parameters | |
---|---|
scale | the texture scale which should be used |