<commit_before>#include <iostream>
#include <GL/glew.h>
#include <GLFW/glfw3.h>

using namespace std;

GLfloat vertices[] = {
    -0.5f, -0.5f, 0.0f,
     0.5f, -0.5f, 0.0f,
     0.0f,  0.5f, 0.0f
};  

GLuint VAO;
GLuint shaderProgram;

void setupOpenGLDrawingCode();
void drawStuff();
GLuint createShader(GLenum shaderType, GLchar** shaderSource);
bool checkShaderCompileStatus(GLuint shader);
bool checkShaderProgramLinkStatus(GLuint shaderProgram);

void key_callback(GLFWwindow* window, int key, int scancode, int action, int mode);

GLchar* vertexShaderSource =  "#version 330 core\n\n\
                                layout (location = 0) in vec3 position;\n\n\
                                void main() {\n\
                                    gl_Position = vec4(position.x, position.y, position.z, 1.0);\n\
                                }";

GLchar* fragmentShaderSource = "#version 330 core\n\n\
                                 out vec4 color;\n\n\
                                 void main() {\n\
                                    color = vec4(1.0f, 0.5f, 0.2f, 1.0f);\n\
                                 }";

int main() {
	glfwInit();
	glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
	glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
	glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
	glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);

	GLFWwindow* window = glfwCreateWindow(800, 600, "LearnOpenGL", NULL, NULL);
	if(window == NULL) {
		cout << "Failed to create GLFW window" << std::endl;
		glfwTerminate();
		return -1;
	}
	glfwMakeContextCurrent(window);

	glewExperimental = GL_TRUE;
	if(glewInit() != GLEW_OK) {
		cout << "Failed to initialize GLEW" << endl;
		return -1;
	}

	glfwSetKeyCallback(window, key_callback);

	glViewport(0, 0, 800, 600);
	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

        setupOpenGLDrawingCode();
        
	while(!glfwWindowShouldClose(window)) {
		glfwPollEvents();
		drawStuff();
		glfwSwapBuffers(window);
	}

	glfwTerminate();

	return 0;
}

void drawStuff() {
	glClear(GL_COLOR_BUFFER_BIT);
        
        glUseProgram(shaderProgram);

        glBindVertexArray(VAO);
        glDrawArrays(GL_TRIANGLES, 0, 3);
        glBindVertexArray(0);
}

void setupOpenGLDrawingCode() {
    
        GLuint VBO;
        glGenBuffers(1, &VBO);
        glGenVertexArrays(1, &VAO);        
        
        glBindVertexArray(VAO);

	glBindBuffer(GL_ARRAY_BUFFER, VBO);
	glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
        glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (GLvoid*)0);
	glEnableVertexAttribArray(0);
        
        glBindVertexArray(0);
        

	GLuint vertexShader = createShader(GL_VERTEX_SHADER, &vertexShaderSource);
	bool vertexShaderCompileSuccess = checkShaderCompileStatus(vertexShader);
        if(!vertexShaderCompileSuccess) {
            cout << "Vertex shader compilation failed" << endl;
        }

        GLuint fragmentShader = createShader(GL_FRAGMENT_SHADER, &fragmentShaderSource);
	bool fragmentShaderCompileSuccess = checkShaderCompileStatus(fragmentShader);
        if(!fragmentShaderCompileSuccess) {
            cout << "Fragment shader compilation failed" << endl;
        }
        
        shaderProgram = glCreateProgram();
        glAttachShader(shaderProgram, vertexShader);
        glAttachShader(shaderProgram, fragmentShader);
        glLinkProgram(shaderProgram);
        
        bool shaderProgramLinkStatus = checkShaderProgramLinkStatus(shaderProgram);
        glDeleteShader(vertexShader);
        glDeleteShader(fragmentShader);
}
<commit_msg>Change tutorial2 to use Element Buffer Objects which store indices into the actual vertex array - helps in eliminating unnecessary duplicate vertex specification<commit_after>#include <iostream>
#include <GL/glew.h>
#include <GLFW/glfw3.h>

using namespace std;

GLfloat vertices[] = {
     0.5f,  0.5f, 0.0f,  // Top Right
     0.5f, -0.5f, 0.0f,  // Bottom Right
    -0.5f, -0.5f, 0.0f,  // Bottom Left
    -0.5f,  0.5f, 0.0f   // Top Left 
};

GLuint indices[] = {  // Note that we start from 0!
    0, 1, 3,   // First Triangle
    1, 2, 3    // Second Triangle
};  

GLuint VAO;
GLuint shaderProgram;

void setupOpenGLDrawingCode();
void drawStuff();
GLuint createShader(GLenum shaderType, GLchar** shaderSource);
bool checkShaderCompileStatus(GLuint shader);
bool checkShaderProgramLinkStatus(GLuint shaderProgram);

void key_callback(GLFWwindow* window, int key, int scancode, int action, int mode);

GLchar* vertexShaderSource =  "#version 330 core\n\n\
                                layout (location = 0) in vec3 position;\n\n\
                                void main() {\n\
                                    gl_Position = vec4(position.x, position.y, position.z, 1.0);\n\
                                }";

GLchar* fragmentShaderSource = "#version 330 core\n\n\
                                 out vec4 color;\n\n\
                                 void main() {\n\
                                    color = vec4(1.0f, 0.5f, 0.2f, 1.0f);\n\
                                 }";

int main() {
	glfwInit();
	glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
	glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
	glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
	glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);

	GLFWwindow* window = glfwCreateWindow(800, 600, "LearnOpenGL", NULL, NULL);
	if(window == NULL) {
		cout << "Failed to create GLFW window" << std::endl;
		glfwTerminate();
		return -1;
	}
	glfwMakeContextCurrent(window);

	glewExperimental = GL_TRUE;
	if(glewInit() != GLEW_OK) {
		cout << "Failed to initialize GLEW" << endl;
		return -1;
	}

	glfwSetKeyCallback(window, key_callback);

	glViewport(0, 0, 800, 600);
	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

        setupOpenGLDrawingCode();
        
	while(!glfwWindowShouldClose(window)) {
		glfwPollEvents();
		drawStuff();
		glfwSwapBuffers(window);
	}

	glfwTerminate();

	return 0;
}

void drawStuff() {
	glClear(GL_COLOR_BUFFER_BIT);
        
        glUseProgram(shaderProgram);
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
        glBindVertexArray(VAO);
        glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
        glBindVertexArray(0);
}

void setupOpenGLDrawingCode() {
        GLuint VBO, EBO;
        glGenBuffers(1, &VBO);
        glGenBuffers(1, &EBO);
        glGenVertexArrays(1, &VAO);        
        
        glBindVertexArray(VAO);

	glBindBuffer(GL_ARRAY_BUFFER, VBO);
        glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
        
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
        glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
        
        glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (GLvoid*)0);
	glEnableVertexAttribArray(0);
        
        glBindVertexArray(0);
        

	GLuint vertexShader = createShader(GL_VERTEX_SHADER, &vertexShaderSource);
	bool vertexShaderCompileSuccess = checkShaderCompileStatus(vertexShader);
        if(!vertexShaderCompileSuccess) {
            cout << "Vertex shader compilation failed" << endl;
        }

        GLuint fragmentShader = createShader(GL_FRAGMENT_SHADER, &fragmentShaderSource);
	bool fragmentShaderCompileSuccess = checkShaderCompileStatus(fragmentShader);
        if(!fragmentShaderCompileSuccess) {
            cout << "Fragment shader compilation failed" << endl;
        }
        
        shaderProgram = glCreateProgram();
        glAttachShader(shaderProgram, vertexShader);
        glAttachShader(shaderProgram, fragmentShader);
        glLinkProgram(shaderProgram);
        
        bool shaderProgramLinkStatus = checkShaderProgramLinkStatus(shaderProgram);
        glDeleteShader(vertexShader);
        glDeleteShader(fragmentShader);
}

{'fraction_non_alphanumeric': 0.10875399361022364, 'fraction_numerical': 0.021853035143769968, 'mean_word_length': 2.795344325897187, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1492095', 'n_tokens_mistral': 2658, 'n_tokens_neox': 2509, 'n_words': 500}