summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkitty piapiac <kcp@bsd.computer>2023-04-17 23:46:30 -0700
committerkitty piapiac <kcp@bsd.computer>2023-04-17 23:46:30 -0700
commit5393ce93d05f9979b7882c686b241f6738011c64 (patch)
treeb68d664d2c5c47490c0dbba8ef72a4974e516210
parentf92b613698b5c4066068bb937b5993b1c5a3bd24 (diff)
mat4 transformations
-rw-r--r--Makefile4
-rw-r--r--graph.c7
-rw-r--r--include/graph.h4
-rw-r--r--mino.c19
4 files changed, 23 insertions, 11 deletions
diff --git a/Makefile b/Makefile
index 2a5adbd..358b282 100644
--- a/Makefile
+++ b/Makefile
@@ -1,8 +1,8 @@
.POSIX:
CC := clang
-CFLAGS := -std=c11 -Wall -Wextra -Wshadow -Iinclude $(shell sdl2-config --cflags)
+CFLAGS := -std=c11 -Wall -Wextra -Wshadow -Iinclude $(shell sdl2-config --cflags) $(shell pkg-config --cflags cglm)
LDFLAGS :=
-LDLIBS := -ldl -lm $(shell sdl2-config --libs)
+LDLIBS := -ldl -lm $(shell sdl2-config --libs) $(shell pkg-config --libs cglm)
all: mino
mino: glad.o tex.o graph.o mino.o
mino.o: mino.c include/mino.h
diff --git a/graph.c b/graph.c
index 92316c3..4e025c9 100644
--- a/graph.c
+++ b/graph.c
@@ -2,6 +2,7 @@
#include<glad/glad.h>
#define SDL_MAIN_HANDLED
#include<SDL.h>
+#include<cglm/cglm.h>
#include"mino.h"
#include"graph.h"
#include"tex.h"
@@ -46,6 +47,8 @@ V graph_deinit(V){SDL_GL_DeleteContext(ctx),SDL_DestroyWindow(win),SDL_Quit();}
V graph_before(V){glClearColor(1.0,0.75,0.8,1.0),glClear(GL_COLOR_BUFFER_BIT);}
V graph_after(V){SDL_GL_SwapWindow(win);}
+U32 graph_ticks(V){R SDL_GetTicks();}
+
_ U32 q_vao,q_vbo,q_ebo;
_ V q_init(V){
_ IM F32 verts[]={
@@ -84,8 +87,8 @@ U32 graph_shader_create(IM C*vert,IM C*frag){I ok;C info[512];U32 v,f,p;
R p;}
V graph_shader_use(U32 s){glUseProgram(s);}
-V graph_shader_seti(IM C*s,I i){I p;glGetIntegerv(GL_CURRENT_PROGRAM,&p),
- glUniform1i(glGetUniformLocation(p,s),i);}
+V graph_shader_setI(IM C*s,I i) {I p;glGetIntegerv(GL_CURRENT_PROGRAM,&p),glUniform1i(glGetUniformLocation(p,s),i);}
+V graph_shader_setM4(IM C*s,mat4 m4){I p;glGetIntegerv(GL_CURRENT_PROGRAM,&p),glUniformMatrix4fv(glGetUniformLocation(p,s),1,GL_FALSE,m4[0]);}
U32 graph_tex_create(IM C*f){Tex tex;U32 t;
glGenTextures(1,&t);
diff --git a/include/graph.h b/include/graph.h
index 61951f5..8e09bac 100644
--- a/include/graph.h
+++ b/include/graph.h
@@ -7,10 +7,12 @@ X V graph_events(V);
X V graph_before(V);
X V graph_after(V);
X V graph_quad(V);
+X U32 graph_ticks(V);
X U32 graph_shader_create(IM C*,IM C*);
X U32 graph_shader_tex;
X V graph_shader_use(U32);
-X V graph_shader_seti(IM C*,I);
+X V graph_shader_setI(IM C*,I);
+X V graph_shader_setM4(IM C*,mat4);
X U32 graph_tex_create(IM C*);
X V graph_tex_use(U32,U8);
diff --git a/mino.c b/mino.c
index 3362ab3..f59a8f0 100644
--- a/mino.c
+++ b/mino.c
@@ -1,5 +1,7 @@
#include<stdio.h>
#include<stdlib.h>
+#include<cglm/affine.h>
+#include<cglm/cglm.h>
#include"mino.h"
#include"graph.h"
@@ -14,7 +16,8 @@ _ IM C shader_tex_vert[]=GRAPH_GLSL(
layout (location=2) in vec2 tex;
out vec3 Col;
out vec2 Tex;
- void main(){gl_Position=vec4(pos,1.0);Col=col;Tex=tex;});
+ uniform mat4 trans;
+ void main(){gl_Position=trans*vec4(pos,1.0);Col=col;Tex=tex;});
_ IM C shader_tex_frag[]=GRAPH_GLSL(
out vec4 Frag;
@@ -27,19 +30,23 @@ _ U32 shader_tex;
_ V shader_tex_init(V){
shader_tex=graph_shader_create(shader_tex_vert,shader_tex_frag),
+ graph_shader_use(shader_tex);
+ mat4 trans;
+ glm_mat4_identity(trans),
+ glm_translate(trans,(vec3){0.5,-0.5,0.5}),
+ glm_rotate(trans,0.2,(vec3){0,0,1}),
+ graph_shader_setM4("trans",trans),
graph_shader_use(shader_tex),
- graph_shader_seti("buf0",0),
- graph_shader_seti("buf1",1);}
+ graph_shader_setI("buf0",0),
+ graph_shader_setI("buf1",1);}
I main(I ac,C**av){(V)ac,(V)av;U32 cat,fart;
graph_init();
atexit(graph_deinit);
-
shader_tex_init();
cat=graph_tex_create("res/tex/cat.jpg");
fart=graph_tex_create("res/tex/fart.jpg");
- WH(1,graph_before(),graph_events(),
- graph_shader_use(shader_tex),
+ WH(1,graph_before(),graph_events();
graph_tex_use(cat,0),
graph_tex_use(fart,1),
graph_quad(),