GLManager.cpp
// Compiles a combination vertex and fragment shader into a single shader program.
Compiles a combination vertex and fragment shader into a single shader program.
Compiles a combination vertex and fragment shader into a single shader program .
GLuint GLManager::CompileShaderProgram(const char rootName [])
{
    GLuint program;
    GLuint vertexShader;
    GLuint fragmentShader;
    std::string vsShader, fsShader;
    std::stringstream vsFilenameStream, fsFilenameStream;
    vsFilenameStream << "shaders/" << rootName << ".vs";
    fsFilenameStream << "shaders/" << rootName << ".fs";
    if (!StringUtility::LoadStringFromFile(vsFilenameStream.str().c_str(), vsShader))
    {
        std::cout << "Could not load " << vsShader << "!" << std::endl;
    }
    if (!StringUtility::LoadStringFromFile(fsFilenameStream.str().c_str(), fsShader))
    {
        std::cout << "Could not load fragment shader" << fsShader << "!" << std::endl;
    }
    const char* vss = vsShader.c_str();
    const char* fss = fsShader.c_str();
    char buffer[1024];
    GLint len;
    GLint compileStatus;
    vertexShader = glCreateShader(GL_VERTEX_SHADER);
    glShaderSource(vertexShader, 1, &vss, NULL);
    glCompileShader(vertexShader);
    glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &compileStatus);
    if (!compileStatus)
    {
        glGetShaderInfoLog(vertexShader, 1024, &len, buffer);
        std::cout << std::endl << "Error: " << glewGetErrorString(glGetError()) << " " << buffer << std::endl;
    }
    fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
    glShaderSource(fragmentShader, 1, &fss, NULL);
    glCompileShader(fragmentShader);
    glGetShaderiv(fragmentShader, GL_COMPILE_STATUS, &compileStatus);
    if (!compileStatus)
    {
        glGetShaderInfoLog(fragmentShader, 1024, &len, buffer);
        std::cout << "Error: " << glewGetErrorString(glGetError()) << " " << buffer << std::endl;
    }
    program = glCreateProgram();
    glAttachShader(program, vertexShader);
    glAttachShader(program, fragmentShader);
    glLinkProgram(program);
    glGetProgramiv(program, GL_LINK_STATUS, &compileStatus);
    if (!compileStatus)
    {
        glGetProgramInfoLog(program, 1024, &len, buffer);
        std::cout << "Error: " << glewGetErrorString(glGetError()) << " " << buffer << std::endl;
    }
    glDeleteShader(vertexShader);
    glDeleteShader(fragmentShader);
    return program;
}
GLuint GLManager :: CompileShaderProgram ( const char rootName [ ] ) { GLuint program ; GLuint vertexShader ; GLuint fragmentShader ; std :: string vsShader , fsShader ; std :: stringstream vsFilenameStream , fsFilenameStream ; vsFilenameStream << " " << rootName << " " ; fsFilenameStream << " " << rootName << " " ; if ( ! StringUtility :: LoadStringFromFile ( vsFilenameStream . str ( ) . c_str ( ) , vsShader ) ) { std :: cout << " " << vsShader << " " << std :: endl ; } if ( ! StringUtility :: LoadStringFromFile ( fsFilenameStream . str ( ) . c_str ( ) , fsShader ) ) { std :: cout << " " << fsShader << " " << std :: endl ; } const char * vss = vsShader . c_str ( ) ; const char * fss = fsShader . c_str ( ) ; char buffer [ 1024 ] ; GLint len ; GLint compileStatus ; vertexShader = glCreateShader ( GL_VERTEX_SHADER ) ; glShaderSource ( vertexShader , 1 , & vss , NULL ) ; glCompileShader ( vertexShader ) ; glGetShaderiv ( vertexShader , GL_COMPILE_STATUS , & compileStatus ) ; if ( ! compileStatus ) { glGetShaderInfoLog ( vertexShader , 1024 , & len , buffer ) ; std :: cout << std :: endl << " " << glewGetErrorString ( glGetError ( ) ) << " " << buffer << std :: endl ; } fragmentShader = glCreateShader ( GL_FRAGMENT_SHADER ) ; glShaderSource ( fragmentShader , 1 , & fss , NULL ) ; glCompileShader ( fragmentShader ) ; glGetShaderiv ( fragmentShader , GL_COMPILE_STATUS , & compileStatus ) ; if ( ! compileStatus ) { glGetShaderInfoLog ( fragmentShader , 1024 , & len , buffer ) ; std :: cout << " " << glewGetErrorString ( glGetError ( ) ) << " " << buffer << std :: endl ; } program = glCreateProgram ( ) ; glAttachShader ( program , vertexShader ) ; glAttachShader ( program , fragmentShader ) ; glLinkProgram ( program ) ; glGetProgramiv ( program , GL_LINK_STATUS , & compileStatus ) ; if ( ! compileStatus ) { glGetProgramInfoLog ( program , 1024 , & len , buffer ) ; std :: cout << " " << glewGetErrorString ( glGetError ( ) ) << " " << buffer << std :: endl ; } glDeleteShader ( vertexShader ) ; glDeleteShader ( fragmentShader ) ; return program ; }
Compiles a combination vertex and fragment shader into a single shader program.
Compiles a combination vertex and fragment shader into a single shader program .
// Create program