examples

Toy examples in single C files.
git clone git://henryandlizzy.uk/examples
Log | Files | Refs

commit 7d6ab667ba562573e922a302b350e4d834c22f9a
parent 22e782262b947e1bf689cb9f6332ef420c273e4d
Author: Henry Wilson <henry@henryandlizzy.uk>
Date:   Fri, 14 Apr 2023 23:06:54 +0100

gl: Add most basic OpenGL example

Diffstat:
MTupfile | 1+
Asrc/gl.c | 27+++++++++++++++++++++++++++
2 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/Tupfile b/Tupfile @@ -5,6 +5,7 @@ CXXFLAGS = -std=c++20 $(COMMON_FLAGS) LDLIBS_aio = -lrt LDLIBS_alsa-simple = -lasound +LDLIBS_gl = -lglfw -lGL LDLIBS_gl-asteroids = -lglfw -lGL -lm -lasound LDLIBS_io_uring = -luring LDLIBS_pulse-async-client = -lpulse diff --git a/src/gl.c b/src/gl.c @@ -0,0 +1,27 @@ +#include <GLFW/glfw3.h> +#include <assert.h> + +static void fb_resize_cb(GLFWwindow*, int w, int h) +{ + glViewport(0, 0, w, h); +} + +int main(int, char* argv[]) +{ + assert(glfwInit()); + GLFWwindow* window = glfwCreateWindow(640, 480, argv[0], NULL, NULL); + assert(window); + glfwSetFramebufferSizeCallback(window, fb_resize_cb); + glfwMakeContextCurrent(window); + glfwSwapInterval(1); + glClearColor(0, 0, 0, 1); + + while (!glfwWindowShouldClose(window)) + { + glfwPollEvents(); + glClear(GL_COLOR_BUFFER_BIT); + glRectd(-.5,-.5, .5, .5); + glfwSwapBuffers(window); + } + glfwTerminate(); /* Implicit window destroy */ +}