diff options
author | kitty piapiac <kcp@bsd.computer> | 2023-04-21 23:50:06 -0700 |
---|---|---|
committer | kitty piapiac <kcp@bsd.computer> | 2023-04-21 23:50:06 -0700 |
commit | 8f38659932677a2b0e00b7f4abda54ac76a8ecd9 (patch) | |
tree | 705767e858a3fe0c89b7b4bc0440012a084c6921 /graph.c | |
parent | 599cde356b576759475d34dbfadb5548926c089d (diff) |
SRS-style rotation skeleton
Diffstat (limited to 'graph.c')
-rw-r--r-- | graph.c | 22 |
1 files changed, 10 insertions, 12 deletions
@@ -15,7 +15,7 @@ _ SDL_Window*win; _ SDL_GLContext ctx; _ V on_err(IM C*d){die("Could not %s: %s",d,SDL_GetError());} -_ V q_init(V); +_ V q_init(V);_ V q_deinit(V); V graph_init(V){SDL_version sdl_vh,sdl_vl; Q(SDL_Init(SDL_INIT_VIDEO),on_err("init sdl2")) SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION,3), @@ -46,7 +46,7 @@ V graph_events(V){SDL_Event ev;U32 t;WH(SDL_PollEvent(&ev),t=ev.type; ||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_deinit(V){q_deinit(),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);} @@ -54,12 +54,10 @@ U32 graph_ticks(V){R SDL_GetTicks();} _ U32 q_vao,q_vbo,q_ebo; _ V q_init(V){ - _ IM F32 verts[]={ - /*positions*/ /*colours*/ /*texture*/ - 0.5, 0.5,0.0, 1.0,0.0,0.0, 1.0,1.0, - 0.5,-0.5,0.0, 0.0,1.0,0.0, 1.0,0.0, - -0.5,-0.5,0.0, 1.0,0.0,1.0, 0.0,0.0, - -0.5, 0.5,0.0, 0.0,0.0,0.0, 0.0,1.0}; + _ IM F32 verts[]={1,1,0, 1,1, + 1,0,0, 1,0, + 0,0,0, 0,0, + 0,1,0, 0,1}; _ IM U32 indxs[]={0,1,3,1,2,3}; glGenVertexArrays(1,&q_vao),glGenBuffers(1,&q_vbo),glGenBuffers(1,&q_ebo); glBindVertexArray(q_vao), @@ -67,13 +65,12 @@ _ V q_init(V){ glBufferData(GL_ARRAY_BUFFER,SZ verts,verts,GL_STATIC_DRAW), glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,q_ebo), glBufferData(GL_ELEMENT_ARRAY_BUFFER,SZ indxs,indxs,GL_STATIC_DRAW); - glVertexAttribPointer(0,3,GL_FLOAT,GL_FALSE,8*SZ(F32),(V*)(0*SZ(F32))), + glVertexAttribPointer(0,3,GL_FLOAT,GL_FALSE,5*SZ(F32),(V*)(0*SZ(F32))), glEnableVertexAttribArray(0), - glVertexAttribPointer(1,3,GL_FLOAT,GL_FALSE,8*SZ(F32),(V*)(3*SZ(F32))), + glVertexAttribPointer(1,2,GL_FLOAT,GL_FALSE,5*SZ(F32),(V*)(3*SZ(F32))), glEnableVertexAttribArray(1), - glVertexAttribPointer(2,2,GL_FLOAT,GL_FALSE,8*SZ(F32),(V*)(6*SZ(F32))), - glEnableVertexAttribArray(2), glBindVertexArray(0);} +_ V q_deinit(V){glDeleteBuffers(1,&q_vao),glDeleteBuffers(1,&q_vbo),glDeleteBuffers(1,&q_ebo);} 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), @@ -96,6 +93,7 @@ U32 graph_shader_create(IM C*vert,IM C*frag){I ok;C info[512];U32 v,f,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_setV3(IM C*s,vec3 v3){I p;glGetIntegerv(GL_CURRENT_PROGRAM,&p),glUniform3f(glGetUniformLocation(p,s),v3[0],v3[1],v3[2]);} 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; |