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/glm.hpp>
|
||||||
#include <glm/gtc/matrix_transform.hpp>
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
#include <glm/gtc/quaternion.hpp>
|
#include <glm/gtc/quaternion.hpp>
|
||||||
|
#include <GLFW/glfw3.h>
|
||||||
|
|
||||||
|
|
||||||
namespace Gloom
|
namespace Gloom
|
||||||
|
|||||||
@@ -5,9 +5,6 @@
|
|||||||
|
|
||||||
void runProgram(GLFWwindow* window)
|
void runProgram(GLFWwindow* window)
|
||||||
{
|
{
|
||||||
// Set GLFW callback mechanism(s)
|
|
||||||
glfwSetKeyCallback(window, keyboardCallback);
|
|
||||||
|
|
||||||
// Enable depth (Z) buffer (accept "closest" fragment)
|
// Enable depth (Z) buffer (accept "closest" fragment)
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
glDepthFunc(GL_LESS);
|
glDepthFunc(GL_LESS);
|
||||||
@@ -16,7 +13,7 @@ void runProgram(GLFWwindow* window)
|
|||||||
glEnable(GL_CULL_FACE);
|
glEnable(GL_CULL_FACE);
|
||||||
|
|
||||||
// Set default colour after clearing the colour buffer
|
// 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.)
|
// Set up your scene here (create Vertex Array Objects, etc.)
|
||||||
|
|
||||||
@@ -30,6 +27,7 @@ void runProgram(GLFWwindow* window)
|
|||||||
|
|
||||||
// Handle other events
|
// Handle other events
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
|
handleKeyboardInput(window);
|
||||||
|
|
||||||
// Flip buffers
|
// Flip buffers
|
||||||
glfwSwapBuffers(window);
|
glfwSwapBuffers(window);
|
||||||
@@ -37,11 +35,10 @@ void runProgram(GLFWwindow* window)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void keyboardCallback(GLFWwindow* window, int key, int scancode,
|
void handleKeyboardInput(GLFWwindow* window)
|
||||||
int action, int mods)
|
|
||||||
{
|
{
|
||||||
// Use escape key for terminating the GLFW 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);
|
glfwSetWindowShouldClose(window, GL_TRUE);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,9 +13,8 @@
|
|||||||
void runProgram(GLFWwindow* window);
|
void runProgram(GLFWwindow* window);
|
||||||
|
|
||||||
|
|
||||||
// GLFW callback mechanisms
|
// Function for handling keypresses
|
||||||
void keyboardCallback(GLFWwindow* window, int key, int scancode,
|
void handleKeyboardInput(GLFWwindow* window);
|
||||||
int action, int mods);
|
|
||||||
|
|
||||||
|
|
||||||
// Checks for whether an OpenGL error occurred. If one did,
|
// Checks for whether an OpenGL error occurred. If one did,
|
||||||
|
|||||||
Reference in New Issue
Block a user