aboutsummaryrefslogtreecommitdiffstats
path: root/yage/core/window.cpp
diff options
context:
space:
mode:
authorYann Herklotz <ymherklotz@gmail.com>2017-12-24 21:04:38 +0000
committerYann Herklotz <ymherklotz@gmail.com>2017-12-24 21:04:38 +0000
commit16915d86d4b866c1fcce7523b0d34e8343ff52fc (patch)
treefdc07bff71840f7336ed5d2e751155635e8ff96a /yage/core/window.cpp
parentddd26ed83d3ac0335562f762ced273a1d62bd959 (diff)
downloadYAGE-16915d86d4b866c1fcce7523b0d34e8343ff52fc.tar.gz
YAGE-16915d86d4b866c1fcce7523b0d34e8343ff52fc.zip
[Code] Simple game example furthered
Diffstat (limited to 'yage/core/window.cpp')
-rw-r--r--yage/core/window.cpp31
1 files changed, 19 insertions, 12 deletions
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 <glad/glad.h>
+#include <GLFW/glfw3.h>
#include <stdexcept>
+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<int>(k)) == GLFW_PRESS) {
+ return true;
}
+
+ return false;
}
} // namespace yage