From 54429ac1abe5c4a7b6ada64e71f9a6e5cee79b59 Mon Sep 17 00:00:00 2001 From: auric <104602845+ihateamongus@users.noreply.github.com> Date: Sat, 6 Sep 2025 21:42:16 -0500 Subject: Add GLFW OpenGL window example --- README.md | 15 ++++++++++++++- main.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 main.c diff --git a/README.md b/README.md index 6238c22..833a9c7 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,15 @@ # opentest -Bloon test + +Sample OpenGL window example using GLFW. + +Compile on macOS: + +``` +clang main.c -o ogl_example -lglfw -framework OpenGL +``` + +Run: + +``` +./ogl_example +``` diff --git a/main.c b/main.c new file mode 100644 index 0000000..3edd036 --- /dev/null +++ b/main.c @@ -0,0 +1,31 @@ +#include +#include + +int main(void) +{ + if (!glfwInit()) { + fprintf(stderr, "Failed to initialize GLFW\n"); + return 1; + } + + GLFWwindow *window = glfwCreateWindow(640, 480, "Hello OpenGL", NULL, NULL); + if (!window) { + fprintf(stderr, "Failed to create window\n"); + glfwTerminate(); + return 1; + } + + glfwMakeContextCurrent(window); + + while (!glfwWindowShouldClose(window)) { + glClear(GL_COLOR_BUFFER_BIT); + + glfwSwapBuffers(window); + + glfwPollEvents(); + } + + glfwDestroyWindow(window); + glfwTerminate(); + return 0; +} -- cgit v1.2.3