How to Shaders

Intro to the engine's shading API - GLSLProgram

Manage shaders via the GLSLProgram

GLSLProgram.hpp - class declarations
GLSLProgram.cpp - class implementation

Example shader implementations

Basic pixel position & color manipulation.

shader.vert
#version 450 core                                         
                                
uniform mat4 model_view;
uniform mat4 projection;
								
layout(location = 0) in vec4 position;

layout(location = 0) out vec4 vertex_pos;
                                    
void main(void)
{
    gl_Position = projection * model_view * position;
    vertex_pos = position;
}

Require the shader class in your application

#include "graphics/shaders/GLSLProgram.hpp"

Instantiate a shader program object

// using default ctor
GLSLProgram shader;

Compile & Build the shader program from your sources

Vertex & Fragment shaders are both enough and mandatory to start with.

std::string and char* sources are accepted can be file path or a shader code as a string

Example

Compile shader from file

// load and compile shaders
shader.CompileShaderFile("res/shaders/example.vert", GLSLShader::GLSLShaderType::VERTEX);
shader.CompileShaderFile("res/shaders/example.frag", GLSLShader::GLSLShaderType::FRAGMENT);

Build the comiled shader

// link the shades into the program
shader.Build();

Use the shader or change the shader that is currently in use

Bind current shader

shader.Enable();

Unbind current shader

shader.Disable();

Last updated