我正在尝试用 OpenGL 和 GLFW 制作一个小游戏引擎。我尝试让输入发挥作用,他们做到了!但它非常笨重,因为您需要对 window 对象的引用,这意味着处理来自 main.cpp 之外的脚本的输入并不方便。
#include<iostream>
#include "inputHeader.h"
#include <GLFW/glfw3.h>
bool GetKey(GLFWwindow* window, int KeyCode)
{
if (glfwGetKey(window, KeyCode) == GLFW_PRESS)
return true;
else
return false;
}
bool GetKeyDown(GLFWwindow* window, int key) {
static bool keyPreviouslyPressed[GLFW_KEY_LAST + 1] = { false };
if (glfwGetKey(window, key) == GLFW_PRESS && !keyPreviouslyPressed[key]) {
keyPreviouslyPressed[key] = true;
return true;
}
return false;
}
//input activation from main.cpp
if (GetKey(window, GLFW_KEY_SPACE))
{
//do stuff
}
如何才能使您不需要引用窗口对象来处理输入?