summaryrefslogtreecommitdiffstats
path: root/graphics/Shader.cpp
diff options
context:
space:
mode:
authorLaG1924 <12997935+LaG1924@users.noreply.github.com>2017-05-10 15:44:51 +0200
committerLaG1924 <12997935+LaG1924@users.noreply.github.com>2017-05-10 15:44:51 +0200
commit469a84c10ba60fba4a513c1b1a0eea600cd7b22f (patch)
tree4de3514353341f68fd63d3c12fa0a162008d3209 /graphics/Shader.cpp
parent2017-04-23 (diff)
downloadAltCraft-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 '')
-rw-r--r--graphics/Shader.cpp36
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() {
+
+}