#include "gfx.hpp" #include #include "io.hpp" GLuint compileShader(const std::string& shaderPath, GLenum shaderType) { GLuint shader; GLint success; std::string shaderSource = readFile(shaderPath); const char* source = shaderSource.c_str(); shader = glCreateShader(shaderType); glShaderSource(shader, 1, &source, NULL); glCompileShader(shader); glGetShaderiv(shader, GL_COMPILE_STATUS, &success); if (!success) { GLchar infoLog[512]; glGetShaderInfoLog(shader, 512, NULL, infoLog); std::cerr << "shader compilation failed" << std::endl << infoLog << std::endl; } return shader; } GLuint compileShaderProgram(const std::string& fragShaderPath) { GLuint vertShader = compileShader("./vert.glsl", GL_VERTEX_SHADER); GLuint fragShader = compileShader(fragShaderPath, GL_FRAGMENT_SHADER); GLuint shaderProgram = glCreateProgram(); glAttachShader(shaderProgram, vertShader); glAttachShader(shaderProgram, fragShader); glLinkProgram(shaderProgram); GLint success; GLchar infoLog[512]; glGetProgramiv(shaderProgram, GL_LINK_STATUS, &success); if (!success) { glGetProgramInfoLog(shaderProgram, 512, NULL, infoLog); std::cerr << "shader linking failed" << std::endl << infoLog << std::endl; exit(-1); } // We no longer need the individual shaders glDeleteShader(vertShader); glDeleteShader(fragShader); return shaderProgram; }