charcoal/OpenGLEngine/Shader.cpp
elipzer b494f68d0c A Working Triangle
Now using GLFW3 instead of the custom window class. This library
looks like it will make development much simpler and will make it
so that I am less worried about my windows code breaking. Currently
setup the http://antongerdelan.net/opengl/hellotriangle.html
tutorial in the MySimpleScene. Will probably create another scene
file to try to get the object oriented stuff working.
2018-09-05 16:26:50 -04:00

54 lines
1.1 KiB
C++

#include "Shader.h"
#include "Exception.h"
Shader::Shader(const std::string& source, ShaderType type)
{
GLenum gl_shader_type;
switch (type)
{
case VERTEX_SHADER:
gl_shader_type = GL_VERTEX_SHADER;
break;
case FRAGMENT_SHADER:
gl_shader_type = GL_FRAGMENT_SHADER;
break;
default:
throw "Invalid Shader Type Specified";
}
m_shader = glCreateShader(gl_shader_type);
const char* c_str = source.c_str();
glShaderSource(m_shader, 1, &c_str, NULL);
glCompileShader(m_shader);
// Make sure that the shader has been compiled successfully
GLint compiled;
glGetShaderiv(m_shader, GL_COMPILE_STATUS, &compiled);
if (compiled != GL_TRUE)
{
char buffer[1024];
GLsizei log_length;
glGetShaderInfoLog(m_shader, 1023, &log_length, buffer);
buffer[log_length] = '\0'; // Add null terminator
OutputDebugString("Error Compiling Shader:\n");
OutputDebugString(buffer);
OutputDebugString("\nSource:\n");
OutputDebugString(source.c_str());
OutputDebugString("\n");
m_shader = 0;
throw EXCEPTION("Error compiling shader.");
}
}
Shader::~Shader()
{
}
GLuint Shader::get_shader() const
{
return m_shader;
}