Changed key polling method from a callback to per-frame

This commit is contained in:
bartvbl
2017-08-23 23:01:59 +02:00
committed by GitHub
3 changed files with 7 additions and 10 deletions

View File

@@ -7,6 +7,7 @@
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/quaternion.hpp>
#include <GLFW/glfw3.h>
namespace Gloom

View File

@@ -5,9 +5,6 @@
void runProgram(GLFWwindow* window)
{
// Set GLFW callback mechanism(s)
glfwSetKeyCallback(window, keyboardCallback);
// Enable depth (Z) buffer (accept "closest" fragment)
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
@@ -16,7 +13,7 @@ void runProgram(GLFWwindow* window)
glEnable(GL_CULL_FACE);
// Set default colour after clearing the colour buffer
glClearColor(0.3f, 0.3f, 0.4f, 1.0f);
glClearColor(0.3f, 0.5f, 0.8f, 1.0f);
// Set up your scene here (create Vertex Array Objects, etc.)
@@ -30,6 +27,7 @@ void runProgram(GLFWwindow* window)
// Handle other events
glfwPollEvents();
handleKeyboardInput(window);
// Flip buffers
glfwSwapBuffers(window);
@@ -37,11 +35,10 @@ void runProgram(GLFWwindow* window)
}
void keyboardCallback(GLFWwindow* window, int key, int scancode,
int action, int mods)
void handleKeyboardInput(GLFWwindow* window)
{
// Use escape key for terminating the GLFW window
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
{
glfwSetWindowShouldClose(window, GL_TRUE);
}

View File

@@ -13,9 +13,8 @@
void runProgram(GLFWwindow* window);
// GLFW callback mechanisms
void keyboardCallback(GLFWwindow* window, int key, int scancode,
int action, int mods);
// Function for handling keypresses
void handleKeyboardInput(GLFWwindow* window);
// Checks for whether an OpenGL error occurred. If one did,