Add some input and make the screen a different color.

This commit is contained in:
Fries 2024-03-09 15:18:50 -08:00
parent f3855d332c
commit 482e000e54

View file

@ -3,6 +3,7 @@
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
void framebuffer_size_callback(GLFWwindow* window, int width, int height); void framebuffer_size_callback(GLFWwindow* window, int width, int height);
void process_input(GLFWwindow* window);
int main() { int main() {
glfwInit(); 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. // Create a render loop, which keeps the program open until glfw tells the loop that the window should close.
while (!glfwWindowShouldClose(window)) { 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. // This swaps completely drawn frames from the "second buffer" to the front one which is displayed on the screen.
glfwSwapBuffers(window); glfwSwapBuffers(window);
// Check if any events are triggered. // 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. // Tell OpenGL the size of the rendering window.
glViewport(0, 0, width, height); glViewport(0, 0, width, height);
} }
void process_input(GLFWwindow* window) {
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) {
glfwSetWindowShouldClose(window, true);
}
}