<commit_before>/*
The MIT License (MIT)

Copyright (c) 2016 <NAME>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*/
#include <MACE/Core/Constants.h>

#include <MACE/Graphics/Window.h>
#include <MACE/Graphics/Renderer.h>

#include <MACE/Utility/BitField.h>

#include <mutex>
#include <ctime>
#include <chrono>
#include <iostream>
#include <unordered_map>
#include <sstream>

#include <GLFW/glfw3.h>

#include <GL/glew.h>

namespace mc {
	namespace os {
		namespace {
			std::unordered_map< short int, BitField > keys = std::unordered_map< short int, BitField >();

			int mouseX = -1;
			int mouseY = -1;

			double scrollX = 0;
			double scrollY = 0;

			void pushKeyEvent(const short int& key, const BitField action) {
				keys[key] = action;
			}
		}//anon namespace

		WindowModule::WindowModule(const int width, const int height, const char* windowTitle) : title(windowTitle), originalWidth(width), originalHeight(height) {}

		void WindowModule::create() {
			window = glfwCreateWindow(originalWidth, originalHeight, title.c_str(), NULL, NULL);

			//first we set up glew and opengl
			glfwMakeContextCurrent(window);

			gfx::ogl::checkGLError(__LINE__, __FILE__);

			glewExperimental = true;
			GLenum result = glewInit();
			if( result != GLEW_OK ) {
				std::ostringstream errorMessage;
				errorMessage << "GLEW failed to initialize: ";
				//to convert from GLubyte* to string, we can use the << in ostream. For some reason the
				//+ operater in std::string can not handle this conversion.
				errorMessage << glewGetErrorString(result);
				throw mc::InitializationError(errorMessage.str());
			}

			try {
				gfx::ogl::checkGLError(__LINE__, __FILE__);
			} catch( ... ) {
				//glew sometimes throws errors that can be ignored (GL_INVALID_ENUM)
			}

			if( !GLEW_VERSION_3_0 ) {
				throw mc::InitializationError("OpenGL 3.0+ not found");
			} else if( !GLEW_VERSION_3_3 ) {
				std::cerr << "OpenGL 3.3 not found, falling back to OpenGL 3.0, which may cause undefined results. Try updating your graphics driver to fix this.";
			} else {
				std::cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << std::endl;
				std::cout << "OpenGL has been created succesfully!" << std::endl;
				std::cout << "Version: " << std::endl << "	" << glGetString(GL_VERSION) << std::endl;
				std::cout << "Vendor: " << std::endl << "	" << glGetString(GL_VENDOR) << std::endl;
				std::cout << "Renderer: " << std::endl << "	" << glGetString(GL_RENDERER) << std::endl;
				std::cout << "Shader version: " << std::endl << "	" << glGetString(GL_SHADING_LANGUAGE_VERSION) << std::endl;
				std::cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << std::endl;
			}
<commit_msg>Improved failed opengl context error message<commit_after>/*
The MIT License (MIT)

Copyright (c) 2016 <NAME>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*/
#include <MACE/Core/Constants.h>

#include <MACE/Graphics/Window.h>
#include <MACE/Graphics/Renderer.h>

#include <MACE/Utility/BitField.h>

#include <mutex>
#include <ctime>
#include <chrono>
#include <iostream>
#include <unordered_map>
#include <sstream>

#include <GLFW/glfw3.h>

#include <GL/glew.h>

namespace mc {
	namespace os {
		namespace {
			std::unordered_map< short int, BitField > keys = std::unordered_map< short int, BitField >();

			int mouseX = -1;
			int mouseY = -1;

			double scrollX = 0;
			double scrollY = 0;

			void pushKeyEvent(const short int& key, const BitField action) {
				keys[key] = action;
			}
		}//anon namespace

		WindowModule::WindowModule(const int width, const int height, const char* windowTitle) : title(windowTitle), originalWidth(width), originalHeight(height) {}

		void WindowModule::create() {
			window = glfwCreateWindow(originalWidth, originalHeight, title.c_str(), NULL, NULL);

			//first we set up glew and opengl
			glfwMakeContextCurrent(window);

			gfx::ogl::checkGLError(__LINE__, __FILE__);

			glewExperimental = true;
			GLenum result = glewInit();
			if( result != GLEW_OK ) {
				std::ostringstream errorMessage;
				errorMessage << "GLEW failed to initialize: ";
				//to convert from GLubyte* to string, we can use the << in ostream. For some reason the
				//+ operater in std::string can not handle this conversion.
				errorMessage << glewGetErrorString(result);
				throw mc::InitializationError(errorMessage.str());
			}

			try {
				gfx::ogl::checkGLError(__LINE__, __FILE__);
			} catch( ... ) {
				//glew sometimes throws errors that can be ignored (GL_INVALID_ENUM)
			}

			if( !GLEW_VERSION_3_0 ) {
				std::ostringstream errorMessage;
				errorMessage << "OpenGL 3.0+ not found. " << std::endl;
				errorMessage << glGetString(GL_VERSION) << " was found instead." << std::endl;
				errorMessage << "This graphics card is not supported." << std::endl;
				//to convert from GLubyte* to string, we can use the << in ostream. For some reason the
				//+ operater in std::string can not handle this conversion.
				throw mc::InitializationError(errorMessage.str());
			} else if( !GLEW_VERSION_3_3 ) {
				std::cerr << "OpenGL 3.3 not found, falling back to OpenGL 3.0, which may cause undefined results. Try updating your graphics driver to fix this.";
			} else {
				std::cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << std::endl;
				std::cout << "OpenGL has been created succesfully!" << std::endl;
				std::cout << "Version: " << std::endl << "	" << glGetString(GL_VERSION) << std::endl;
				std::cout << "Vendor: " << std::endl << "	" << glGetString(GL_VENDOR) << std::endl;
				std::cout << "Renderer: " << std::endl << "	" << glGetString(GL_RENDERER) << std::endl;
				std::cout << "Shader version: " << std::endl << "	" << glGetString(GL_SHADING_LANGUAGE_VERSION) << std::endl;
				std::cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << std::endl;
			}

{'fraction_non_alphanumeric': 0.1493915848116112, 'fraction_numerical': 0.005571030640668524, 'mean_word_length': 4.247692307692308, 'pattern_counts': {'":': 0, '<': 169, '<?xml version=': 0, '>': 33, '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': '1842800', 'n_tokens_mistral': 2333, 'n_tokens_neox': 2060, 'n_words': 666}