From 16915d86d4b866c1fcce7523b0d34e8343ff52fc Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Sun, 24 Dec 2017 21:04:38 +0000 Subject: [Code] Simple game example furthered --- yage/core/window.cpp | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) (limited to 'yage/core/window.cpp') diff --git a/yage/core/window.cpp b/yage/core/window.cpp index 70e8d8e3..f2f22e3b 100644 --- a/yage/core/window.cpp +++ b/yage/core/window.cpp @@ -7,23 +7,21 @@ */ #include "window.h" +#include "input.h" + +#include +#include #include +using std::runtime_error; + namespace yage { void key_callback(GLFWwindow *window, int key, int scanCode, int action, int mods) { - if (key == GLFW_KEY_E && (action == GLFW_REPEAT || action == GLFW_PRESS)) { - glClearColor(0.5f, 0.f, 0.f, 1.f); - } else if (key == GLFW_KEY_Q && - (action == GLFW_REPEAT || action == GLFW_PRESS)) { - glClearColor(0.f, 0.f, 0.5f, 1.f); - } else { - glClearColor(0.f, .5f, 0.f, 1.f); - } } Window::Window() = default; @@ -37,7 +35,7 @@ Window::~Window() void Window::create(std::string window_name, int width, int height) { if (glfwInit() == GLFW_FALSE) { - throw std::runtime_error("GLFW Initialisation failed"); + throw runtime_error("GLFW Initialisation failed"); } glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); @@ -47,7 +45,7 @@ void Window::create(std::string window_name, int width, int height) window_ = glfwCreateWindow(width, height, window_name.c_str(), nullptr, nullptr); if (window_ == nullptr) { - throw std::runtime_error("GLFW Window creation failed"); + throw runtime_error("GLFW Window creation failed"); } // initialize the gl context @@ -101,10 +99,19 @@ bool Window::shouldClose() void Window::pollEvents() const { glfwPollEvents(); +} - if (glfwGetKey(window_, GLFW_KEY_W) == GLFW_PRESS) { - glClearColor(0.f, 0.5f, 0.5f, 1.f); +bool Window::keyPressed(key k) +{ + if (window_ == nullptr) { + throw runtime_error("Window is not initialized"); + } + + if (glfwGetKey(window_, static_cast(k)) == GLFW_PRESS) { + return true; } + + return false; } } // namespace yage -- cgit From 354d7df4d2779ed7391701d1ef4344e959b64582 Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Wed, 27 Dec 2017 19:21:12 +0000 Subject: [Broken] Texture is black. --- yage/core/window.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'yage/core/window.cpp') diff --git a/yage/core/window.cpp b/yage/core/window.cpp index f2f22e3b..5db75074 100644 --- a/yage/core/window.cpp +++ b/yage/core/window.cpp @@ -7,7 +7,7 @@ */ #include "window.h" -#include "input.h" +#include "../data/input.h" #include #include @@ -61,7 +61,7 @@ void Window::create(std::string window_name, int width, int height) glfwSwapInterval(1); // set the clear colour to black - glClearColor(0.f, 0.5f, 0.f, 1.f); + glClearColor(0.18f, 0.18f, 0.18f, 1.f); // set alpha blending glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); -- cgit From 9038ee45f93b1ae07a28a516781676ebe3a67536 Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Sun, 31 Dec 2017 18:17:04 +0000 Subject: [Bug] Fixed null pointers in spritebatch. --- yage/core/window.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'yage/core/window.cpp') diff --git a/yage/core/window.cpp b/yage/core/window.cpp index 5db75074..d8f3a7e8 100644 --- a/yage/core/window.cpp +++ b/yage/core/window.cpp @@ -58,7 +58,7 @@ void Window::create(std::string window_name, int width, int height) glfwSetKeyCallback(window_, key_callback); // set vsync on - glfwSwapInterval(1); + glfwSwapInterval(0); // set the clear colour to black glClearColor(0.18f, 0.18f, 0.18f, 1.f); -- cgit From 86e4aa6265ade205aba94494a7a31a83b5686387 Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Wed, 3 Jan 2018 13:26:37 +0000 Subject: [Engine] [Example] Reenabled vsync and working on example. --- yage/core/window.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'yage/core/window.cpp') diff --git a/yage/core/window.cpp b/yage/core/window.cpp index d8f3a7e8..5db75074 100644 --- a/yage/core/window.cpp +++ b/yage/core/window.cpp @@ -58,7 +58,7 @@ void Window::create(std::string window_name, int width, int height) glfwSetKeyCallback(window_, key_callback); // set vsync on - glfwSwapInterval(0); + glfwSwapInterval(1); // set the clear colour to black glClearColor(0.18f, 0.18f, 0.18f, 1.f); -- cgit From 7b95e3a9eacf296f215c73e5d8ad9090a24adb20 Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Thu, 4 Jan 2018 21:36:30 +0000 Subject: [Engine] Now using stb_image to laod all kinds of textures. --- yage/core/window.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'yage/core/window.cpp') diff --git a/yage/core/window.cpp b/yage/core/window.cpp index 5db75074..711e1294 100644 --- a/yage/core/window.cpp +++ b/yage/core/window.cpp @@ -19,11 +19,20 @@ using std::runtime_error; namespace yage { +namespace { + void key_callback(GLFWwindow *window, int key, int scanCode, int action, int mods) { } +void framebuffer_size_callback(GLFWwindow *window, int width, int height) +{ + glViewport(0, 0, width, height); +} + +} // namespace + Window::Window() = default; Window::~Window() @@ -56,6 +65,8 @@ void Window::create(std::string window_name, int width, int height) // set key callback glfwSetKeyCallback(window_, key_callback); + // set resize callback + glfwSetFramebufferSizeCallback(window_, framebuffer_size_callback); // set vsync on glfwSwapInterval(1); -- cgit