diff options
author | lonkaars <loek@pipeframe.xyz> | 2024-05-15 14:23:20 +0200 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2024-05-15 14:23:20 +0200 |
commit | 0a5c176456b7afe024910183392d59116c37088e (patch) | |
tree | 4ac1f5241f7b015e0aba7b00e79333a3d88a918c | |
parent | 3ca23ebf8123cf909a057ba6fe833d64aedcb957 (diff) |
more hello world (pink window)
-rw-r--r-- | die.c | 16 | ||||
-rw-r--r-- | die.h | 5 | ||||
-rw-r--r-- | main.c | 29 | ||||
-rw-r--r-- | makefile | 3 |
4 files changed, 51 insertions, 2 deletions
@@ -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); +} + @@ -0,0 +1,5 @@ +#pragma once + +/** @brief print error and exit */ +void die(const char*, ...); + @@ -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; } @@ -1,11 +1,12 @@ LDFLAGS += -lglfw +LDFLAGS += -lOpenGL .PHONY: FORCE all: main FORCE main: main.o - +main: die.o clean: FORCE git clean -fxdi |