diff options
author | Yann Herklotz <ymherklotz@gmail.com> | 2017-09-20 23:01:12 +0100 |
---|---|---|
committer | Yann Herklotz <ymherklotz@gmail.com> | 2017-09-20 23:01:12 +0100 |
commit | 977b8f16d7ef43101b6ef588f9610f34285fa7e6 (patch) | |
tree | 25446bc027685765a79492d3b68c49bdee53612b /yage/base/window.cpp | |
parent | b869c926429e9316617a643960a97fad64dd42ef (diff) | |
download | YAGE-977b8f16d7ef43101b6ef588f9610f34285fa7e6.tar.gz YAGE-977b8f16d7ef43101b6ef588f9610f34285fa7e6.zip |
Replacing SDL by glfw
Diffstat (limited to 'yage/base/window.cpp')
-rw-r--r-- | yage/base/window.cpp | 55 |
1 files changed, 12 insertions, 43 deletions
diff --git a/yage/base/window.cpp b/yage/base/window.cpp index a8b6fc02..67f32bb2 100644 --- a/yage/base/window.cpp +++ b/yage/base/window.cpp @@ -6,8 +6,7 @@ * ---------------------------------------------------------------------------- */ -#include <yage/base/window.h> -#include <GL/glew.h> +#include "window.h" #include <iostream> #include <stdexcept> @@ -19,60 +18,30 @@ Window::Window() = default; Window::~Window() { - SDL_DestroyWindow(window_); + glfwDestroyWindow(window_); } void Window::create(const std::string &window_name, int width, int height, unsigned flags) { - Uint32 gl_window_states = 0; + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); - // set the correct input flags - if (flags & WindowFlags::SHOWN) { - gl_window_states |= SDL_WINDOW_OPENGL; - } - if (flags & WindowFlags::HIDDEN) { - gl_window_states |= SDL_WINDOW_HIDDEN; - } - if (flags & WindowFlags::FULLSCREEN) { - gl_window_states |= SDL_WINDOW_FULLSCREEN; - } - if (flags & WindowFlags::BORDERLESS) { - gl_window_states |= SDL_WINDOW_BORDERLESS; - } - - // SDL_GL options - - // SDL_GL_SetAttribute (SDL_GL_CONTEXT_MAJOR_VERSION, 4); - // SDL_GL_SetAttribute (SDL_GL_CONTEXT_MINOR_VERSION, 5); - SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); - - // create the SDL window - window_ = SDL_CreateWindow(window_name.c_str(), SDL_WINDOWPOS_CENTERED, - SDL_WINDOWPOS_CENTERED, width, height, - gl_window_states); + window_ = glfwCreateWindow(width, height, window_name.c_str(), nullptr, nullptr); if (window_ == nullptr) { - throw std::runtime_error("SDL_CreateWindow failed"); + throw std::runtime_error("GLFW Window creation failed"); } - // initialize the GL context in the window - SDL_GLContext gl_context = SDL_GL_CreateContext(window_); - if (gl_context == nullptr) { - throw std::runtime_error("SDL_GL_CreateContext failed"); - } - - // initialize glew - GLenum error = glewInit(); - if (error != GLEW_OK) { - throw std::runtime_error("glewInit failed"); - } + // initialize the gl context + glfwMakeContextCurrent(window_); // print out the current OpenGL version to debug std::cout << "*** OpenGL version: " << glGetString(GL_VERSION) << " ***\n"; - // set vsync on instead of custom fps limiting - SDL_GL_SetSwapInterval(1); + // set vsync on + glfwSwapInterval(1); + // set the clear color to black glClearColor(0.f, 0.5f, 0.f, 1.f); // set alpha blending @@ -83,7 +52,7 @@ void Window::create(const std::string &window_name, int width, int height, void Window::swapBuffer() { // swap the window buffer - SDL_GL_SwapWindow(window_); + glfwSwapBuffers(window_); } void Window::clearBuffer() |