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/program.cpp

50 lines
1.0 KiB
C++
Raw Normal View History

2015-11-07 14:11:23 +00:00
#include "program.hpp"
2015-11-09 15:06:34 +00:00
#include "shader.hpp"
#include <fstream>
2015-11-11 17:28:11 +00:00
const std::string Program::filename(const std::string &name)
2015-11-07 14:11:23 +00:00
{
2015-11-11 17:28:11 +00:00
return "/data/shaders/" + name;
}
2015-11-13 11:20:00 +00:00
Program::Program(const std::string &name)
2015-11-11 17:28:11 +00:00
{
const std::string path = filename(name) + '/';
2015-11-09 15:06:34 +00:00
const Shader vertex_shader = Shader(GL_VERTEX_SHADER, (path + "vertex.glsl").c_str());
const Shader fragment_shader = Shader(GL_FRAGMENT_SHADER, (path + "fragment.glsl").c_str());
2015-11-07 14:11:23 +00:00
_id = glCreateProgram();
2015-11-09 15:06:34 +00:00
glAttachShader(_id, vertex_shader.id());
glAttachShader(_id, fragment_shader.id());
2015-11-07 14:11:23 +00:00
2015-11-09 15:06:34 +00:00
std::ifstream file(path + "attrib.txt", std::ios::in);
std::string line;
int index = 0;
while (std::getline(file, line))
glBindAttribLocation(_id, index++, line.c_str());
2015-11-07 14:11:23 +00:00
2015-11-09 15:06:34 +00:00
for (int i = 0; i < index; ++i)
glEnableVertexAttribArray(i);
2015-11-07 14:11:23 +00:00
}
void Program::use() const
{
glUseProgram(_id);
}
2015-11-13 11:23:22 +00:00
void Program::link()
{
glLinkProgram(_id);
}
2015-11-07 14:11:23 +00:00
GLuint Program::get_uniform_location(const GLchar *name) const
{
return glGetUniformLocation(_id, name);
}