I have a bit of a problem.
Im trying to make a small game and to sum it up my GLFWwindow* window
is a Game.h class variable.
If I understand it correctly (or at least thats how it works for me) in order to use different window callback functions such as:
glfwSetFramebufferSizeCallback()
glfwSetKeyCallback()
I need to pass static functions i.e static void key_callback(GLFWwindow* window, int, int, int, int)
as their parameter.
So this function looks somewhat like this:
void Game::key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) //this is declared as static
{
if (key == GLFW_KEY_F11 && action == GLFW_PRESS) {
changeScreen();
}
if (key == GLFW_KEY_M && action == GLFW_PRESS) {
changeMouse();
}
}
and changeScreen()
translates into:
void Game::changeScreen()
{
screenState = !screenState;
if (screenState) {
glfwSetWindowMonitor(window, 0, 200, 200, 600, 600, GLFW_DONT_CARE);
}
else {
glfwSetWindowMonitor(window, glfwGetPrimaryMonitor(), 0, 0, 2560, 1440, GLFW_DONT_CARE);
}
}
The problem is that window
as well as changeScreen()
and its variables are not static and thus I cant use them.
Therefore the easiest way to solve it would be how I did with all of my other keys, for example:
if (glfwGetKey(this->window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
{
glfwSetWindowShouldClose(this->window, GLFW_TRUE);
}
So I need to somehow be able to detect the key press only once using this method. I am open to any other solutions to my problem. But If there was some dumb way (this really doesnt need to work extremely reliably) I would like to use it since at this stage reworking the project and making the window global or at least not a member of class would give me a headache.