From 1a8ec165031af3b860028ef1b360acc8e7baf9e6 Mon Sep 17 00:00:00 2001 From: TravisBot <> Date: Thu, 21 Sep 2017 23:32:46 +0000 Subject: Rebuilding documentation --- yage/base/window.cpp | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 yage/base/window.cpp (limited to 'yage/base/window.cpp') diff --git a/yage/base/window.cpp b/yage/base/window.cpp new file mode 100644 index 00000000..67f32bb2 --- /dev/null +++ b/yage/base/window.cpp @@ -0,0 +1,66 @@ +/* ---------------------------------------------------------------------------- + * window.cpp + * + * Copyright (c) 2017 Yann Herklotz Grave -- MIT License + * See file LICENSE for more details + * ---------------------------------------------------------------------------- + */ + +#include "window.h" + +#include +#include + +namespace yage +{ + +Window::Window() = default; + +Window::~Window() +{ + glfwDestroyWindow(window_); +} + +void Window::create(const std::string &window_name, int width, int height, + unsigned flags) +{ + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); + + window_ = glfwCreateWindow(width, height, window_name.c_str(), nullptr, nullptr); + if (window_ == nullptr) { + throw std::runtime_error("GLFW Window creation 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 + glfwSwapInterval(1); + + // set the clear color to black + glClearColor(0.f, 0.5f, 0.f, 1.f); + // set alpha blending + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); +} + +void Window::swapBuffer() +{ + // swap the window buffer + glfwSwapBuffers(window_); +} + +void Window::clearBuffer() +{ + // set the clear depth + glClearDepth(1.f); + // clears buffer with clear color + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); +} + +} // namespace yage -- cgit