| 126 | } |
| 127 | |
| 128 | bool InitOpenGL(int resolutionX, int resolutionY, const std::string &windowName) { |
| 129 | // Initialise GLFW |
| 130 | ASSERT(glfwInit(), "GLFW Init failed.\n"); |
| 131 | glfwSetErrorCallback(&glfwError); |
| 132 | |
| 133 | // TODO: Disable MSAA for now until texture array adds padding |
| 134 | //wglfwWindowHint(GLFW_SAMPLES, 4); |
| 135 | |
| 136 | #ifdef __APPLE__ |
| 137 | glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); |
| 138 | glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); |
| 139 | glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // Appease the OSX Gods |
| 140 | glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); |
| 141 | #else |
| 142 | // TODO: If we fail to create a GL context on Windows, fall back to not requesting any (Keiiko Bug #1) |
| 143 | //glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_COMPAT_PROFILE); |
| 144 | #endif |
| 145 | |
| 146 | window = glfwCreateWindow(resolutionX, resolutionY, windowName.c_str(), nullptr, nullptr); |
| 147 | |
| 148 | if (window == nullptr) { |
| 149 | LOG(WARNING) << "Failed to create a GLFW window."; |
| 150 | getchar(); |
| 151 | glfwTerminate(); |
| 152 | return false; |
| 153 | } |
| 154 | glfwMakeContextCurrent(window); |
| 155 | |
| 156 | glfwSetWindowSizeCallback(window, window_size_callback); |
| 157 | |
| 158 | // Initialize GLEW |
| 159 | glewExperimental = GL_TRUE; // Needed for core profile |
| 160 | |
| 161 | if (glewInit() != GLEW_OK) { |
| 162 | LOG(WARNING) << "Failed to initialize GLEW"; |
| 163 | getchar(); |
| 164 | glfwTerminate(); |
| 165 | return false; |
| 166 | } |
| 167 | |
| 168 | // Ensure we can capture the escape key being pressed below |
| 169 | glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE); |
| 170 | // Set the mouse at the center of the screen |
| 171 | glfwPollEvents(); |
| 172 | |
| 173 | // Dark blue background |
| 174 | glClearColor(1.0f, 1.0f, 1.0f, 1.0f); |
| 175 | |
| 176 | // Enable depth test |
| 177 | glEnable(GL_DEPTH_TEST); |
| 178 | // Accept fragment if it closer to the camera than the former one |
| 179 | glDepthFunc(GL_LESS); |
| 180 | |
| 181 | glEnable(GL_BLEND); |
| 182 | glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); |
| 183 | |
| 184 | GLint texture_units, max_array_texture_layers; |
| 185 | glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &texture_units); |
nothing calls this directly
no outgoing calls
no test coverage detected