From 68081ef4f1f51b5753e25a1be6f870eb2e84f76e Mon Sep 17 00:00:00 2001 From: lonkaars Date: Thu, 16 May 2024 19:31:31 +0200 Subject: experiment with vertex shader --- fill.vert | 10 ++++++++++ hello.frag | 8 -------- hello.vert | 7 ------- main.c | 12 ++++++------ makefile | 8 ++++---- visuals.frag | 8 ++++++++ 6 files changed, 28 insertions(+), 25 deletions(-) create mode 100644 fill.vert delete mode 100644 hello.frag delete mode 100644 hello.vert create mode 100644 visuals.frag diff --git a/fill.vert b/fill.vert new file mode 100644 index 0000000..5633fd5 --- /dev/null +++ b/fill.vert @@ -0,0 +1,10 @@ +#version 330 core +layout (location = 0) in vec3 vert; + +void main() { + // Setting w to 0 has the effect of an infinitely large zoom, which makes the + // single triangle fill the viewport completely. This is okay since I only + // care about the fragment shader. + gl_Position = vec4(vert.xyz, 0.0); +} + diff --git a/hello.frag b/hello.frag deleted file mode 100644 index 3539bdc..0000000 --- a/hello.frag +++ /dev/null @@ -1,8 +0,0 @@ -#version 330 core - -#include "config.h" - -void main() { - gl_FragColor = vec4(gl_FragCoord.x / WIDTH, gl_FragCoord.y / HEIGHT, 0, 1); -} - diff --git a/hello.vert b/hello.vert deleted file mode 100644 index 4af0bdf..0000000 --- a/hello.vert +++ /dev/null @@ -1,7 +0,0 @@ -#version 330 core -layout (location = 0) in vec3 aPos; - -void main() { - gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0); -} - diff --git a/main.c b/main.c index 0ff0706..09cf2fb 100644 --- a/main.c +++ b/main.c @@ -6,14 +6,14 @@ #include "die.h" #include "config.h" -#include "hello_vert.h" -#include "hello_frag.h" +#include "fill_vert.h" +#include "visuals_frag.h" void prepare_tri() { const float vertices[] = { + 0, 1, 0, + 1, -1, 0, -1, -1, 0, - 3, -1, 0, - -1, 3, 0, }; // initialize vertex {buffer,attribute} object buffers @@ -59,8 +59,8 @@ int main(int argc, char** argv) { // prepare shaders GLuint shader = link_shaders( - vert_shader(hello_vert, hello_vert_size), - frag_shader(hello_frag, hello_frag_size) + vert_shader(fill_vert, fill_vert_size), + frag_shader(visuals_frag, visuals_frag_size) ); // main draw loop diff --git a/makefile b/makefile index 34c19bf..fa39ee9 100644 --- a/makefile +++ b/makefile @@ -12,12 +12,12 @@ all: main FORCE main: main.o main: die.o main: shader.o -main: hello_frag.o -main: hello_vert.o +main: visuals_frag.o +main: fill_vert.o # fix compile order -main.o: hello_vert.h -main.o: hello_frag.h +main.o: fill_vert.h +main.o: visuals_frag.h %.s %.h &: %.spv ./blob $< $* diff --git a/visuals.frag b/visuals.frag new file mode 100644 index 0000000..3539bdc --- /dev/null +++ b/visuals.frag @@ -0,0 +1,8 @@ +#version 330 core + +#include "config.h" + +void main() { + gl_FragColor = vec4(gl_FragCoord.x / WIDTH, gl_FragCoord.y / HEIGHT, 0, 1); +} + -- cgit v1.2.3