summaryrefslogtreecommitdiff
path: root/graph.c
diff options
context:
space:
mode:
authorkitty piapiac <kcp@bsd.computer>2023-04-18 01:59:53 -0700
committerkitty piapiac <kcp@bsd.computer>2023-04-18 01:59:53 -0700
commit84bcb0274fc80d360ff0fbe5ede89643169f6165 (patch)
treea600a6a2211e8520f5275ea1704439a245cf28ce /graph.c
parent5393ce93d05f9979b7882c686b241f6738011c64 (diff)
window projection
Diffstat (limited to 'graph.c')
-rw-r--r--graph.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/graph.c b/graph.c
index 4e025c9..78965fd 100644
--- a/graph.c
+++ b/graph.c
@@ -2,6 +2,8 @@
#include<glad/glad.h>
#define SDL_MAIN_HANDLED
#include<SDL.h>
+#include<cglm/affine.h>
+#include<cglm/cam.h>
#include<cglm/cglm.h>
#include"mino.h"
#include"graph.h"
@@ -23,7 +25,7 @@ V graph_init(V){SDL_version sdl_vh,sdl_vl;
N(win=SDL_CreateWindow("mino",SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED,graph_win_w,graph_win_h,SDL_WINDOW_OPENGL|SDL_WINDOW_RESIZABLE),on_err("create window"))
N(ctx=SDL_GL_CreateContext(win),on_err("create OpenGL context"))
N(gladLoadGLLoader(SDL_GL_GetProcAddress),on_err("load GL"))
- SDL_GL_SetSwapInterval(1);
+ SDL_GL_SetSwapInterval(1),
q_init();
SDL_VERSION(&sdl_vh)SDL_GetVersion(&sdl_vl);
fprintf(stderr,
@@ -41,7 +43,8 @@ V graph_events(V){SDL_Event ev;U32 t;WH(SDL_PollEvent(&ev),t=ev.type;
Q(SDL_QUIT==t,exit(0))OR
Q(SDL_WINDOWEVENT==t,SDL_WindowEvent ew=ev.window;
Q(SDL_WINDOWEVENT_RESIZED==ew.event
- ||SDL_WINDOWEVENT_SIZE_CHANGED==ew.event,graph_win_w=ew.data1,graph_win_h=ew.data2,glViewport(0,0,ew.data1,ew.data2))))}
+ ||SDL_WINDOWEVENT_SIZE_CHANGED==ew.event,graph_win_w=ew.data1,graph_win_h=ew.data2,
+ glViewport(0,0,ew.data1,ew.data2))))}
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);}
@@ -71,7 +74,12 @@ _ V q_init(V){
glVertexAttribPointer(2,2,GL_FLOAT,GL_FALSE,8*SZ(F32),(V*)(6*SZ(F32))),
glEnableVertexAttribArray(2),
glBindVertexArray(0);}
-V graph_quad(){
+V graph_quad_xywh(F32 x,F32 y,F32 w,F32 h){graph_quad((vec2){x,y},(vec2){w,h});}
+V graph_quad(vec2 p,vec2 z){mat4 trans;
+ glm_mat4_identity(trans),
+ glm_translate(trans,(vec3){p[0],p[1],0}),
+ glm_scale(trans,(vec3){z[0],z[1],1}),
+ graph_shader_setM4("model",trans),
glBindVertexArray(q_vao),
glDrawElements(GL_TRIANGLES,6,GL_UNSIGNED_INT,0),
glBindVertexArray(0);}
@@ -87,8 +95,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_setM4(IM C*s,mat4 m4){I p;glGetIntegerv(GL_CURRENT_PROGRAM,&p),glUniformMatrix4fv(glGetUniformLocation(p,s),1,GL_FALSE,m4[0]);}
+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][0]);}
U32 graph_tex_create(IM C*f){Tex tex;U32 t;
glGenTextures(1,&t);