From 482e000e54269f58cb394dfd0dc63e091c29223d Mon Sep 17 00:00:00 2001 From: Fries Date: Sat, 9 Mar 2024 15:18:50 -0800 Subject: [PATCH] Add some input and make the screen a different color. --- src/main.cc | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main.cc b/src/main.cc index 38b2842..1d0699a 100644 --- a/src/main.cc +++ b/src/main.cc @@ -3,6 +3,7 @@ #include void framebuffer_size_callback(GLFWwindow* window, int width, int height); +void process_input(GLFWwindow* window); int main() { glfwInit(); @@ -40,6 +41,14 @@ int main() { // Create a render loop, which keeps the program open until glfw tells the loop that the window should close. while (!glfwWindowShouldClose(window)) { + // Process input. + process_input(window); + + // Set the GL state to use this color when clearing the screen. + glClearColor(0.2f, 0.3f, 0.3f, 1.0f); + // Clear the screen and use the color from the state. + glClear(GL_COLOR_BUFFER_BIT); + // This swaps completely drawn frames from the "second buffer" to the front one which is displayed on the screen. glfwSwapBuffers(window); // Check if any events are triggered. @@ -54,3 +63,9 @@ void framebuffer_size_callback(GLFWwindow* window, int width, int height) { // Tell OpenGL the size of the rendering window. glViewport(0, 0, width, height); } + +void process_input(GLFWwindow* window) { + if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) { + glfwSetWindowShouldClose(window, true); + } +}