Shader - Horizon-NTH/HorizonGUI GitHub Wiki
The Shader
class in the hgui::kernel
namespace facilitates the creation, management,
and utilization of shader programs. It is capable of loading and using vertex, fragment,
and geometry shaders in your rendering pipeline. The class is defined in the header file Shader.h
.
-
Shader(const std::string& vertexShader, const std::string& fragmentShader, const std::string& geometryShader)
: Constructs aShader
object by specifying the source code for the vertex, fragment, and geometry shaders. This constructor compiles and links the shaders to create a shader program.
-
Shader& use()
: Sets the shader program as the current one for rendering. -
GLuint get_id() const
: Retrieves the ID of the shader program. -
Shader& set_int(const std::string& uniformName, int i)
: Sets an integer uniform variable in the shader. -
Shader& set_float(const std::string& uniformName, float f)
: Sets a floating-point uniform variable in the shader. -
Shader& set_vec2(const std::string& uniformName, const vec2& vec2)
: Sets a vec2 uniform variable in the shader. -
Shader& set_vec2(const std::string& uniformName, const point& vec2)
: Sets a point (consider as a vec2) uniform variable in the shader. -
Shader& set_vec2(const std::string& uniformName, const size& vec2)
: Sets a size (consider as a vec2) uniform variable in the shader. -
Shader& set_vec3(const std::string& uniformName, const vec3& vec3)
: Sets a vec3 uniform variable in the shader. -
Shader& set_vec3(const std::string& uniformName, const color& vec3)
: Sets a color (consider as a vec3) uniform variable in the shader. -
Shader& set_vec4(const std::string& uniformName, const vec4& vec4)
: Sets a vec4 uniform variable in the shader. -
Shader& set_vec4(const std::string& uniformName, const color& vec4)
: Sets a color (consider as a vec4) uniform variable in the shader. -
Shader& set_double(const std::string& uniformName, double d)
: Sets a double precision floating-point uniform variable in the shader. -
Shader& set_dvec2(const std::string& uniformName, const dvec2& dvec2)
: Sets a dvec2 uniform variable in the shader. -
Shader& set_dvec2(const std::string& uniformName, const Point<double>& dvec2)
: Sets a point (consider as a dvec2) uniform variable in the shader. -
Shader& set_dvec2(const std::string& uniformName, const Size<double>& dvec2)
: Sets a dvec2 (consider as a dvec2) uniform variable in the shader. -
Shader& set_dvec3(const std::string& uniformName, const dvec3& dvec3)
: Sets a dvec3 uniform variable in the shader. -
Shader& set_dvec3(const std::string& uniformName, const Color<double>& dvec3)
: Sets a color (consider as a dvec3) uniform variable in the shader. -
Shader& set_dvec4(const std::string& uniformName, const dvec4& dvec4)
: Sets a vec4 uniform variable in the shader. -
Shader& set_dvec4(const std::string& uniformName, const Color<double>& dvec4)
: Sets a color (consider as a dvec4) uniform variable in the shader. -
Shader& set_mat4(const std::string& uniformName, const glm::mat4& mat4)
: Sets a glm 4x4 matrix uniform variable in the shader.
#include <hgui/header/Shader.h>
// Example Usage of Shader class
std::string vertexShaderCode = /* vertex shader source code */;
std::string fragmentShaderCode = /* fragment shader source code */;
std::string geometryShaderCode = /* geometry shader source code */;
hgui::kernel::Shader shader(vertexShaderCode, fragmentShaderCode, geometryShaderCode);
shader.use();
// Set uniform variables
shader.set_int("intUniform", 42);
shader.set_float("floatUniform", 3.14f).set_vec3("color", hgui::kernel::vec3(1.0f, 0.0f, 0.0f));
// Render with the shader
Note: In the "Example Usage" section, make sure to replace
/* vertex shader source code */
,/* fragment shader source code */
, and/* geometry shader source code */
with actual shader source code strings. Also, modify the uniform variable names and values as per your application requirements.