0
\$\begingroup\$

I am trying to write a simple C++ game using OpenGL. In my render loop i ask for text based input from the user but this causes the GLFW window to become unresponsive. I suspect that this happens because the window does not like it when the main thread is paused from std::cin so it behaves weirdly. If i remove the input prompt the window behaves perfectly. Can someone confirm if this is the case and what workarounds are there to fix it?

\$\endgroup\$
1
\$\begingroup\$

Yes. Your program is waiting for the user to give their input before continuing.

The workaround to this is to use asynchronous input.

An example of this in GLFW is to use something like this:

// Set the callback glfwSetKeyCallback(g_odin.windowManager.g_window, key_callback);
// The function that gets called on key events void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) { /* ... do something ... */ }

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.