aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2024-05-15 14:23:20 +0200
committerlonkaars <loek@pipeframe.xyz>2024-05-15 14:23:20 +0200
commit0a5c176456b7afe024910183392d59116c37088e (patch)
tree4ac1f5241f7b015e0aba7b00e79333a3d88a918c
parent3ca23ebf8123cf909a057ba6fe833d64aedcb957 (diff)
more hello world (pink window)
-rw-r--r--die.c16
-rw-r--r--die.h5
-rw-r--r--main.c29
-rw-r--r--makefile3
4 files changed, 51 insertions, 2 deletions
diff --git a/die.c b/die.c
new file mode 100644
index 0000000..0635b31
--- /dev/null
+++ b/die.c
@@ -0,0 +1,16 @@
+#include <stdio.h>
+#include <stdarg.h>
+#include <stdlib.h>
+
+#include "die.h"
+
+void die(const char* fmt, ...) {
+ va_list args;
+ va_start(args, fmt);
+ vfprintf(stderr, fmt, args);
+ fflush(stderr);
+ va_end(args);
+
+ exit(EXIT_FAILURE);
+}
+
diff --git a/die.h b/die.h
new file mode 100644
index 0000000..a3f391d
--- /dev/null
+++ b/die.h
@@ -0,0 +1,5 @@
+#pragma once
+
+/** @brief print error and exit */
+void die(const char*, ...);
+
diff --git a/main.c b/main.c
index be899de..3beddeb 100644
--- a/main.c
+++ b/main.c
@@ -1,5 +1,12 @@
+#include <stdlib.h>
#include <GLFW/glfw3.h>
+#include "die.h"
+
+void resize_handler(GLFWwindow* window, int width, int height) {
+ glViewport(0, 0, width, height);
+}
+
int main(int argc, char** argv) {
glfwInit();
@@ -8,6 +15,26 @@ int main(int argc, char** argv) {
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
- return 0;
+ int width = 800, height = 600;
+ GLFWwindow* window = glfwCreateWindow(width, height, "vis", NULL, NULL);
+
+ if (window == NULL) {
+ glfwTerminate();
+ die("error: could not create window\n");
+ }
+
+ glfwMakeContextCurrent(window);
+ glfwSetFramebufferSizeCallback(window, resize_handler);
+ resize_handler(window, width, height);
+
+ while (!glfwWindowShouldClose(window)) {
+ glClearColor(1.f, 0.f, 1.f, 1.0f);
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ glfwSwapBuffers(window);
+ }
+
+ glfwTerminate();
+ return EXIT_SUCCESS;
}
diff --git a/makefile b/makefile
index 4525ae0..684dab0 100644
--- a/makefile
+++ b/makefile
@@ -1,11 +1,12 @@
LDFLAGS += -lglfw
+LDFLAGS += -lOpenGL
.PHONY: FORCE
all: main FORCE
main: main.o
-
+main: die.o
clean: FORCE
git clean -fxdi