Binary_Code_GT_Generator/Render_GT_Color_Mesh_to_GT_Img/render_related_source/shader.hpp
Shader(const char* vertexPath, const char* fragmentPath)
    {
        // 1. retrieve the vertex/fragment source code from filePath
        std::string vertexCode;
        std::string fragmentCode;
        std::ifstream vShaderFile;
        std::ifstream fShaderFile;
        // ensure ifstream objects can throw exceptions:
        vShaderFile.exceptions (std::ifstream::failbit | std::ifstream::badbit);
        fShaderFile.exceptions (std::ifstream::failbit | std::ifstream::badbit);
        try 
        {
            // open files
            vShaderFile.open(vertexPath);
            fShaderFile.open(fragmentPath);
            std::stringstream vShaderStream, fShaderStream;
            // read file's buffer contents into streams
            vShaderStream << vShaderFile.rdbuf();
            fShaderStream << fShaderFile.rdbuf();
            // close file handlers
            vShaderFile.close();
            fShaderFile.close();
            // convert stream into string
            vertexCode   = vShaderStream.str();
            fragmentCode = fShaderStream.str();
        }
        catch (std::ifstream::failure e)
        {
            std::cout << "ERROR::SHADER::FILE_NOT_SUCCESFULLY_READ" << std::endl;
        }
        const char* vShaderCode = vertexCode.c_str();
        const char * fShaderCode = fragmentCode.c_str();
        // 2. compile shaders
        unsigned int vertex, fragment;
        int success;
        char infoLog[512];
        // vertex shader
        vertex = glCreateShader(GL_VERTEX_SHADER);
        glShaderSource(vertex, 1, &vShaderCode, NULL);
        glCompileShader(vertex);
        checkCompileErrors(vertex, "VERTEX");
        // fragment Shader
        fragment = glCreateShader(GL_FRAGMENT_SHADER);
        glShaderSource(fragment, 1, &fShaderCode, NULL);
        glCompileShader(fragment);
        checkCompileErrors(fragment, "FRAGMENT");
        // shader Program
        ID = glCreateProgram();
        glAttachShader(ID, vertex);
        glAttachShader(ID, fragment);
        glLinkProgram(ID);
        checkCompileErrors(ID, "PROGRAM");
        // delete the shaders as they're linked into our program now and no longer necessary
        //glDeleteShader(vertex);
        //glDeleteShader(fragment);
    }
// constructor generates the shader on the fly
// ------------------------------------------------------------------------
constructor generates the shader on the fly
constructor generates the shader on the fly
Shader(const char* vertexPath, const char* fragmentPath)
    {
        std::string vertexCode;
        std::string fragmentCode;
        std::ifstream vShaderFile;
        std::ifstream fShaderFile;
        vShaderFile.exceptions (std::ifstream::failbit | std::ifstream::badbit);
        fShaderFile.exceptions (std::ifstream::failbit | std::ifstream::badbit);
        try 
        {
            vShaderFile.open(vertexPath);
            fShaderFile.open(fragmentPath);
            std::stringstream vShaderStream, fShaderStream;
            vShaderStream << vShaderFile.rdbuf();
            fShaderStream << fShaderFile.rdbuf();
            vShaderFile.close();
            fShaderFile.close();
            vertexCode   = vShaderStream.str();
            fragmentCode = fShaderStream.str();
        }
        catch (std::ifstream::failure e)
        {
            std::cout << "ERROR::SHADER::FILE_NOT_SUCCESFULLY_READ" << std::endl;
        }
        const char* vShaderCode = vertexCode.c_str();
        const char * fShaderCode = fragmentCode.c_str();
        unsigned int vertex, fragment;
        int success;
        char infoLog[512];
        vertex = glCreateShader(GL_VERTEX_SHADER);
        glShaderSource(vertex, 1, &vShaderCode, NULL);
        glCompileShader(vertex);
        checkCompileErrors(vertex, "VERTEX");
        fragment = glCreateShader(GL_FRAGMENT_SHADER);
        glShaderSource(fragment, 1, &fShaderCode, NULL);
        glCompileShader(fragment);
        checkCompileErrors(fragment, "FRAGMENT");
        ID = glCreateProgram();
        glAttachShader(ID, vertex);
        glAttachShader(ID, fragment);
        glLinkProgram(ID);
        checkCompileErrors(ID, "PROGRAM");
    }
Shader ( const char * vertexPath , const char * fragmentPath ) { std :: string vertexCode ; std :: string fragmentCode ; std :: ifstream vShaderFile ; std :: ifstream fShaderFile ; vShaderFile . exceptions ( std :: ifstream :: failbit | std :: ifstream :: badbit ) ; fShaderFile . exceptions ( std :: ifstream :: failbit | std :: ifstream :: badbit ) ; try { vShaderFile . open ( vertexPath ) ; fShaderFile . open ( fragmentPath ) ; std :: stringstream vShaderStream , fShaderStream ; vShaderStream << vShaderFile . rdbuf ( ) ; fShaderStream << fShaderFile . rdbuf ( ) ; vShaderFile . close ( ) ; fShaderFile . close ( ) ; vertexCode = vShaderStream . str ( ) ; fragmentCode = fShaderStream . str ( ) ; } catch ( std :: ifstream :: failure e ) { std :: cout << " " << std :: endl ; } const char * vShaderCode = vertexCode . c_str ( ) ; const char * fShaderCode = fragmentCode . c_str ( ) ; unsigned int vertex , fragment ; int success ; char infoLog [ 512 ] ; vertex = glCreateShader ( GL_VERTEX_SHADER ) ; glShaderSource ( vertex , 1 , & vShaderCode , NULL ) ; glCompileShader ( vertex ) ; checkCompileErrors ( vertex , " " ) ; fragment = glCreateShader ( GL_FRAGMENT_SHADER ) ; glShaderSource ( fragment , 1 , & fShaderCode , NULL ) ; glCompileShader ( fragment ) ; checkCompileErrors ( fragment , " " ) ; ID = glCreateProgram ( ) ; glAttachShader ( ID , vertex ) ; glAttachShader ( ID , fragment ) ; glLinkProgram ( ID ) ; checkCompileErrors ( ID , " " ) ; }
constructor generates the shader on the fly
constructor generates the shader on the fly
// 1. retrieve the vertex/fragment source code from filePath // ensure ifstream objects can throw exceptions: // open files // read file's buffer contents into streams // close file handlers // convert stream into string // 2. compile shaders // vertex shader // fragment Shader // shader Program // delete the shaders as they're linked into our program now and no longer necessary //glDeleteShader(vertex); //glDeleteShader(fragment);