daily update on 20230609 by nitload youmu, graphic arragement for better form init
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
当然可以。下面是一个使用 glfwSetWindowCloseCallback 函数的代码示例
|
||||
|
||||
// 定义一个关闭回调函数
|
||||
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
|
||||
{
|
||||
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
|
||||
glfwSetWindowShouldClose(window, GLFW_TRUE); // 设置窗口的关闭标记为真
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
// 初始化GLFW和创建窗口
|
||||
glfwInit();
|
||||
GLFWwindow* window = glfwCreateWindow(800, 600, "My Title", NULL, NULL);
|
||||
|
||||
// 设置当前上下文和初始化GLAD
|
||||
glfwMakeContextCurrent(window);
|
||||
gladLoadGL(glfwGetProcAddress);
|
||||
|
||||
// 设置关闭回调函数
|
||||
glfwSetWindowCloseCallback(window, key_callback);
|
||||
|
||||
// 主循环
|
||||
while (!glfwWindowShouldClose(window))
|
||||
{
|
||||
// 渲染代码
|
||||
|
||||
// 交换缓冲区和处理事件
|
||||
glfwSwapBuffers(window);
|
||||
glfwPollEvents();
|
||||
}
|
||||
|
||||
// 销毁窗口和终止GLFW
|
||||
glfwDestroyWindow(window);
|
||||
glfwTerminate();
|
||||
}
|
||||
|
||||
这段代码会在用户按下ESC键时关闭窗口。
|
||||
如果您想要隐藏窗口而不是关闭,您可以在关闭回调函数中使用 glfwHideWindow 函数
|
||||
。如果您想要重新显示窗口,您可以在其他地方使用 glfwShowWindow 函数。
|
||||
Reference in New Issue
Block a user