Dengine/src/Shader.cpp

41 lines
772 B
C++
Raw Normal View History

2016-06-03 05:07:40 +00:00
#include <Dengine\Shader.h>
#include <fstream>
#include <iostream>
namespace Dengine
{
Shader::Shader()
: program(0)
2016-06-03 05:07:40 +00:00
{
}
Shader::~Shader() {}
2016-06-03 05:07:40 +00:00
i32 Shader::loadProgram(GLuint vertexShader, GLuint fragmentShader)
2016-06-03 05:07:40 +00:00
{
this->program = glCreateProgram();
glAttachShader(this->program, vertexShader);
glAttachShader(this->program, fragmentShader);
glLinkProgram(this->program);
2016-06-03 05:07:40 +00:00
glDeleteShader(fragmentShader);
glDeleteShader(vertexShader);
2016-06-03 05:07:40 +00:00
GLint success;
GLchar infoLog[512];
glGetProgramiv(this->program, GL_LINK_STATUS, &success);
2016-06-03 05:07:40 +00:00
if (!success)
{
glGetProgramInfoLog(this->program, 512, NULL, infoLog);
2016-06-03 05:07:40 +00:00
std::cout << "glLinkProgram failed: " << infoLog << std::endl;
return -1;
2016-06-03 05:07:40 +00:00
}
return 0;
2016-06-03 05:07:40 +00:00
}
2016-06-03 05:07:40 +00:00
2016-06-08 07:29:16 +00:00
void Shader::use() const { glUseProgram(this->program); }
2016-06-03 05:07:40 +00:00
}