mirror of
https://github.com/brammie15/VoxelRenderer.git
synced 2025-12-16 18:01:49 +01:00
Changed key polling method from a callback to per-frame
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user