2023-07-31 00:08:17 +02:00
|
|
|
#include "gfx.hpp"
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
#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;
|
|
|
|
}
|
|
|
|
|
2023-08-06 13:08:49 +02:00
|
|
|
GLuint compileShaderProgram(const std::string& fragShaderPath)
|
2023-07-31 00:08:17 +02:00
|
|
|
{
|
|
|
|
GLuint vertShader = compileShader("./vert.glsl", GL_VERTEX_SHADER);
|
2023-08-06 13:08:49 +02:00
|
|
|
GLuint fragShader = compileShader(fragShaderPath, GL_FRAGMENT_SHADER);
|
2023-07-31 00:08:17 +02:00
|
|
|
|
|
|
|
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;
|
2023-08-03 10:26:27 +02:00
|
|
|
exit(-1);
|
2023-07-31 00:08:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// We no longer need the individual shaders
|
|
|
|
glDeleteShader(vertShader);
|
|
|
|
glDeleteShader(fragShader);
|
|
|
|
|
|
|
|
return shaderProgram;
|
|
|
|
}
|
|
|
|
|