<commit_before>#ifndef GLHELPER_H
#define GLHELPER_H

#include <stdio.h>
#include <stdlib.h>
#include <GL/glew.h>
#include <GL/glut.h>

#include <iostream>

#include "textfile.h"

using namespace std;

namespace GLSLShader {
    enum GLSLShaderType {
        VERTEX, FRAGMENT, GEOMETRY,TESS_CONTROL, TESS_EVALUATION
    };
};

bool GLCompileShaderFromFile( GLuint & shader, char const * fileName, GLSLShader::GLSLShaderType type ){
    bool bRet;

    if( GLSLShader::VERTEX == type ){
        shader = glCreateShader(GL_VERTEX_SHADER);
    }else if( GLSLShader::FRAGMENT == type ){
        shader = glCreateShader(GL_FRAGMENT_SHADER);
    }

    char * sourceText = 0;
    sourceText = textFileRead( fileName );
    char const * sourceTextConst = sourceText;
    glShaderSource( shader, 1, &sourceTextConst, NULL);	
    free(sourceText);
    
    glCompileShader(shader);
    GLint result;
    glGetShaderiv( shader, GL_COMPILE_STATUS, &result );
    if( GL_FALSE == result ){
        cerr<< "shader compilation failed!" <<endl;
        GLint logLen;
        glGetShaderiv( shader, GL_INFO_LOG_LENGTH, &logLen );
        if( logLen > 0 ){
            char * log = (char *)malloc(logLen);
            GLsizei written;
            glGetShaderInfoLog( shader, logLen, &written, log);
            cerr << "Shader log: \n" << log <<endl;
            free(log);
        }
        bRet = false;
    }else{
        bRet = true;
    }
    return bRet;
}

bool GLCreateProgram( GLuint & program ){
    program = glCreateProgram();
    if( 0 == program ){
        cerr<< "Error creating program object" <<endl;
        return false;
    }else{
        return true;
    }
}

bool GLLinkUseProgram( GLuint & program ){
    glLinkProgram(program);
    GLint status;
    glGetProgramiv( program, GL_LINK_STATUS, &status );
    if( GL_FALSE == status ){
        cerr << "Failed to link shader program!" <<endl;
        GLint logLen;
        glGetProgramiv( program, GL_INFO_LOG_LENGTH, &logLen);
        if( logLen > 0 ){
            char * log = (char *)malloc(logLen);
            GLsizei written;
            glGetProgramInfoLog( program, logLen, &written, log);
            cerr<< "Program log: \n" << log <<endl;
            free(log);
        }
        return false;
    }else{
        glUseProgram(program);
        return true;
    }
}

void GLPrintInfo(){
    const char * p_glversion = (const char * ) glGetString(GL_VERSION);
    cout << "GL Version: " << p_glversion <<endl;
}

#endif<commit_msg>added functions to GLHelper<commit_after>#ifndef GLHELPER_H
#define GLHELPER_H

#include <stdio.h>
#include <stdlib.h>
#include <GL/glew.h>
#include <GL/glut.h>

#include <iostream>

#include "textfile.h"

using namespace std;

namespace GLSLShader {
    enum GLSLShaderType {
        VERTEX, FRAGMENT, GEOMETRY,TESS_CONTROL, TESS_EVALUATION
    };
};

bool GLCompileShaderFromString( GLuint & shader, char const * Source, GLSLShader::GLSLShaderType type ){
    bool bRet;

    if( GLSLShader::VERTEX == type ){
        shader = glCreateShader(GL_VERTEX_SHADER);
    }else if( GLSLShader::FRAGMENT == type ){
        shader = glCreateShader(GL_FRAGMENT_SHADER);
    }

    char const * sourceTextConst = Source;
    glShaderSource( shader, 1, &sourceTextConst, NULL);	
    
    glCompileShader(shader);
    GLint result;
    glGetShaderiv( shader, GL_COMPILE_STATUS, &result );
    if( GL_FALSE == result ){
        cerr<< "shader compilation failed!" <<endl;
        GLint logLen;
        glGetShaderiv( shader, GL_INFO_LOG_LENGTH, &logLen );
        if( logLen > 0 ){
            char * log = (char *)malloc(logLen);
            GLsizei written;
            glGetShaderInfoLog( shader, logLen, &written, log);
            cerr << "Shader log: \n" << log <<endl;
            free(log);
        }
        bRet = false;
    }else{
        bRet = true;
    }
    return bRet;
}

bool GLCompileShaderFromFile( GLuint & shader, char const * fileName, GLSLShader::GLSLShaderType type ){
    bool bRet;
    char * sourceText = 0;
    sourceText = textFileRead( fileName );
    char const * sourceTextConst = sourceText;
    bRet = GLCompileShaderFromString( shader, sourceTextConst, type );
    free(sourceText);
    return bRet;
}

bool GLCreateProgram( GLuint & program ){
    program = glCreateProgram();
    if( 0 == program ){
        cerr<< "Error creating program object" <<endl;
        return false;
    }else{
        return true;
    }
}

bool GLLinkProgram( GLuint & program ){
    glLinkProgram(program);
    GLint status;
    glGetProgramiv( program, GL_LINK_STATUS, &status );
    if( GL_FALSE == status ){
        cerr << "Failed to link shader program!" <<endl;
        GLint logLen;
        glGetProgramiv( program, GL_INFO_LOG_LENGTH, &logLen);
        if( logLen > 0 ){
            char * log = (char *)malloc(logLen);
            GLsizei written;
            glGetProgramInfoLog( program, logLen, &written, log);
            cerr<< "Program log: \n" << log <<endl;
            free(log);
        }
        return false;
    }else{
        return true;
    }
}
bool GLLinkUseProgram( GLuint & program ){
    if( true == GLLinkProgram( program ) ){
        glUseProgram(program);
        return true;
    }else{
        return false;
    }
}

void GLUseProgram( GLuint & program ){
    glUseProgram(program);
}

void GLPrintInfo(){
    const char * p_glversion = (const char * ) glGetString(GL_VERSION);
    cout << "GL Version: " << p_glversion <<endl;
}

#endif
{'fraction_non_alphanumeric': 0.1166575242274639, 'fraction_numerical': 0.0018284878405558603, 'mean_word_length': 2.617724867724868, 'pattern_counts': {'":': 0, '<': 73, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3695575', 'n_tokens_mistral': 1778, 'n_tokens_neox': 1751, 'n_words': 446}