diff options
author | LaG1924 <12997935+LaG1924@users.noreply.github.com> | 2017-05-10 15:44:51 +0200 |
---|---|---|
committer | LaG1924 <12997935+LaG1924@users.noreply.github.com> | 2017-05-10 15:44:51 +0200 |
commit | 469a84c10ba60fba4a513c1b1a0eea600cd7b22f (patch) | |
tree | 4de3514353341f68fd63d3c12fa0a162008d3209 /graphics/Shader.cpp | |
parent | 2017-04-23 (diff) | |
download | AltCraft-469a84c10ba60fba4a513c1b1a0eea600cd7b22f.tar AltCraft-469a84c10ba60fba4a513c1b1a0eea600cd7b22f.tar.gz AltCraft-469a84c10ba60fba4a513c1b1a0eea600cd7b22f.tar.bz2 AltCraft-469a84c10ba60fba4a513c1b1a0eea600cd7b22f.tar.lz AltCraft-469a84c10ba60fba4a513c1b1a0eea600cd7b22f.tar.xz AltCraft-469a84c10ba60fba4a513c1b1a0eea600cd7b22f.tar.zst AltCraft-469a84c10ba60fba4a513c1b1a0eea600cd7b22f.zip |
Diffstat (limited to 'graphics/Shader.cpp')
-rw-r--r-- | graphics/Shader.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/graphics/Shader.cpp b/graphics/Shader.cpp new file mode 100644 index 0000000..2b72917 --- /dev/null +++ b/graphics/Shader.cpp @@ -0,0 +1,36 @@ +#include <GL/glew.h> +#include <iostream> +#include <fstream> +#include "Shader.hpp" + +Shader::Shader(std::string fileName, bool vertex) { + this->isVertex = vertex; + std::ifstream in(fileName); + if (!in){ + std::cout<<"Can't open shader source at "<<fileName<<std::endl; + throw 519; + } + shaderSource = std::string((std::istreambuf_iterator<char>(in)), + std::istreambuf_iterator<char>()); + shaderId = glCreateShader(isVertex?GL_VERTEX_SHADER:GL_FRAGMENT_SHADER); + const char* shaderSrc = shaderSource.c_str(); + glShaderSource(shaderId, 1, &shaderSrc, NULL); + glCompileShader(shaderId); + GLint success; + GLchar infoLog[512]; + glGetShaderiv(shaderId, GL_COMPILE_STATUS, &success); + if(!success) + { + glGetShaderInfoLog(shaderId, 512, NULL, infoLog); + std::cout << "ERROR::SHADER::VERTEX::COMPILATION_FAILED\n" << infoLog << std::endl; + throw 518; + } +} + +Shader::~Shader() { + glDeleteShader(shaderId); +} + +void Shader::bind() { + +} |