From 0a5c176456b7afe024910183392d59116c37088e Mon Sep 17 00:00:00 2001 From: lonkaars Date: Wed, 15 May 2024 14:23:20 +0200 Subject: more hello world (pink window) --- die.c | 16 ++++++++++++++++ die.h | 5 +++++ main.c | 29 ++++++++++++++++++++++++++++- makefile | 3 ++- 4 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 die.c create mode 100644 die.h 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 +#include +#include + +#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 #include +#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 -- cgit v1.2.3