/// <summary> /// Loads the shader from source file. /// </summary> /// <param name="file">Path to the source file.</param> /// <param name="type">Type of shader (VERTEX/FRAGMENT SHADER).</param> /// <returns>Shader ID</returns> GLuint Shader::LoadShader(const ustring & file, GLuint type) { std::ifstream input; input.exceptions(std::ifstream::failbit | std::ifstream::badbit); std::string srcCode; try { input.open(file.c_str()); srcCode.assign((std::istreambuf_iterator<char>(input)), (std::istreambuf_iterator<char>())); } catch (std::ifstream::failure e) { ucout << "Could not read shader file!\n"; } GLuint sID = glCreateShader(type); const char * code = srcCode.c_str(); glShaderSource(sID, 1, (const GLchar**)&code, NULL); glCompileShader(sID); ValidateCompile(sID); return sID; }
bool GLShader::LoadShader(const GLchar* source) { GLenum type = GLShaderType(m_info.type); if (type == GL_NONE) { DebugPrintF(VTEXT("Failed to Load Shader due to invalid type\n")); return false; } /*create shader object*/ m_shader = glCreateShader(type); /*put shader source into memory*/ glShaderSource(m_shader, 1, &source, NULL); /*cleanup allocated source*/ /*compile shader*/ glCompileShader(m_shader); return ValidateCompile(m_shader); }