1
0
Fork 0
This repository has been archived on 2023-03-27. You can view files and clone it, but cannot push or open issues or pull requests.
matabstrix/src/shader.cpp

33 lines
728 B
C++
Raw Permalink Normal View History

2015-11-07 14:11:23 +00:00
#include "shader.hpp"
#include <cstdlib>
#include <cstdio>
2015-11-13 14:40:50 +00:00
const std::string Shader::filename(const std::string &name)
2015-11-07 14:11:23 +00:00
{
2015-11-16 13:05:04 +00:00
return "/shaders/" + name;
2015-11-13 14:40:50 +00:00
}
2015-11-16 13:05:04 +00:00
Shader::Shader(const Adapter &adapter, const std::string &name)
2015-11-13 14:40:50 +00:00
{
const GLuint type = name.substr(name.size() - 5) == ".vert" ? GL_VERTEX_SHADER : GL_FRAGMENT_SHADER;
2015-11-16 13:05:04 +00:00
FILE *file = fopen(adapter.filename<Shader>(name).c_str(), "r");
2015-11-07 14:11:23 +00:00
fseek(file, 0, SEEK_END);
const long size = ftell(file);
fseek(file, 0, SEEK_SET);
char *source = (char*)malloc(size + 1);
fread(source, size, 1, file);
source[size] = 0;
fclose(file);
_id = glCreateShader(type);
glShaderSource(_id, 1, (const GLchar**)&source, nullptr);
glCompileShader(_id);
free(source);
}