diff options
| author | realtradam <[email protected]> | 2022-11-24 23:25:23 -0500 |
|---|---|---|
| committer | realtradam <[email protected]> | 2022-11-24 23:25:23 -0500 |
| commit | 6e1d0c6a3f3699e44000f411cd93261c460f75a9 (patch) | |
| tree | 30ba89e71ef19a074cb2e6c9a8dbb8d08cccdab7 /src/window.cpp | |
| parent | f2a9e986afe980c6b32f7f40d1fe2b0294d86d90 (diff) | |
| download | Ogle-6e1d0c6a3f3699e44000f411cd93261c460f75a9.tar.gz Ogle-6e1d0c6a3f3699e44000f411cd93261c460f75a9.zip | |
cleaned up code
Diffstat (limited to 'src/window.cpp')
| -rw-r--r-- | src/window.cpp | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/window.cpp b/src/window.cpp new file mode 100644 index 0000000..adc51c0 --- /dev/null +++ b/src/window.cpp @@ -0,0 +1,55 @@ +#include "glad/glad.h" +#include "GLFW/glfw3.h" + +#include <iostream> + +namespace Window { + namespace { // private + GLFWwindow* window; + + void framebuffer_size_callback(GLFWwindow* window, int width, int height) + { + glViewport(0, 0, width, height); + } + } + + GLFWwindow* get() + { + return window; + } + + int init( + unsigned int width, + unsigned int height, + const char* title + ) + { + glfwInit(); + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); // 4.6 is highest + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); + glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); + + window = glfwCreateWindow(width, height, title, NULL, NULL); + if (window == NULL) + { + std::cout << "Failed to create GLFW window" << std::endl; + glfwTerminate(); + return -1; + } + glfwMakeContextCurrent(window); + + if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) + { + std::cout << "Failed to init GLAD" << std::endl; + return -1; + } + + glViewport(0, 0, 800, 600); + + glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); + + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + return 0; + } +} |
