GLFW3 has a glfwWaitEvents
that will probably do what you want.
http://www.glfw.org/docs/latest/group__window.html#ga554e37d781f0a997656c26b2c56c835e
문제
In order to hold the result open (the window screen) I have to do the following:
while (glfwGetWindowParam(GLFW_OPENED))
{
// do some stuff
glDrawPixels(...);
glfwSwapBuffers();
}
But this loops through the body of the while loop until I stop it. I don't want to render in real time.
Does GLFW have an equivalent to the SDL_WaitEvent:
SDL_Surface* screen;
// do something with screen
SDL_Flip(screen);
SDL_Event event;
while (SDL_WaitEvent(&event))
{
// handle input
}
If I try to do something like this, the program renders the result but after a while it stops responding:
//do stuff
glDrawPixels(...);
glfwSwapBuffers();
while (glfwGetWindowParam(GLFW_OPENED))
{
if (glfwGetKey(GLFW_KEY_ESC) == GLFW_PRESS)
{
glfwTerminate();
}
}
해결책 2
GLFW3 has a glfwWaitEvents
that will probably do what you want.
http://www.glfw.org/docs/latest/group__window.html#ga554e37d781f0a997656c26b2c56c835e
다른 팁
Your typical GLFW main application loop should probably look something like this:
while (!glfwWindowShouldClose(window)) {
glfwPollEvents();
update();
draw();
glfwSwapBuffers(window);
}
glfwDestroyWindow(window);
Input can be handled via a callback such as the keyboard input callback. I use a wrapper class to handle my GLFW stuff so after I create a window I do something like this:
glfwSetWindowUserPointer(window, this);
glfwSetKeyCallback(window, glfwKeyCallback);
And my keyboard callback looks like this:
void glfwKeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods) {
GlfwApp * instance = (GlfwApp *) glfwGetWindowUserPointer(window);
instance->onKey(key, scancode, action, mods);
}
and the base class implementation of the onKey method looks like this:
void GlfwApp::onKey(int key, int scancode, int action, int mods) {
if (GLFW_PRESS != action) {
return;
}
switch (key) {
case GLFW_KEY_ESCAPE:
glfwSetWindowShouldClose(window, 1);
return;
}
}
Instead of using glfwGetWindowParam() I think you may want to look into using glfwWindowShouldClose(). It takes in a pointer to the GLFW window. Here's a link to the GLFW docs page that has glfwWindowShouldClose() http://www.glfw.org/docs/latest/group__window.html