diff options
-rw-r--r-- | Makefile | 6 | ||||
-rw-r--r-- | include/scene.h | 6 | ||||
-rw-r--r-- | mino.c | 42 | ||||
-rw-r--r-- | scene-title.c | 49 | ||||
-rw-r--r-- | scene.c | 4 |
5 files changed, 68 insertions, 39 deletions
@@ -4,10 +4,12 @@ CFLAGS := -std=c11 -g -O0 -Wall -Wextra -Wshadow -Iinclude $(shell sdl2-config LDFLAGS := LDLIBS := -ldl -lm $(shell sdl2-config --libs) $(shell pkg-config --libs cglm) all: mino -mino: glad.o tex.o graph.o mino.o +mino: glad.o tex.o graph.o scene.o scene-title.o mino.o mino.o: mino.c include/mino.h +scene.o: scene.c include/scene.h +scene-title.o: scene-title.c graph.o: graph.c include/graph.h tex.o: tex.c include/tex.h glad.o: glad.c include/glad/glad.h clean: - rm -rf mino mino.o graph.o tex.o glad.o + rm -rf mino mino.o scene-title.o scene.o graph.o tex.o glad.o diff --git a/include/scene.h b/include/scene.h new file mode 100644 index 0000000..fb4f7c1 --- /dev/null +++ b/include/scene.h @@ -0,0 +1,6 @@ +#ifndef MINO_SCENE_H +#define MINO_SCENE_H +typedef struct scene Scene; +struct scene{IM C*n;Scene*(*f)(V);}; +X V scene_run(Scene*); +#endif @@ -4,47 +4,15 @@ #include<cglm/cglm.h> #include"mino.h" #include"graph.h" +#include"scene.h" NR V die(IM C*f,...)VA(f,vfprintf(stderr,f,ap),fputc('\n',stderr),exit(1)) V*make(Uz z){V*p;N(p=malloc(z), die("oom"))R p;} V*remk(V*p,Uz z){N(p=realloc(p,z),die("oom"))R p;} V del(V*p){free(p);} -_ IM C shader_tex_vert[]=GRAPH_GLSL( - layout (location=0) in vec3 pos; - layout (location=1) in vec3 col; - layout (location=2) in vec2 tex; - out vec3 Col; - out vec2 Tex; - uniform mat4 proj; - uniform mat4 model; - void main(){gl_Position=proj*model*vec4(pos,1.0);Col=col;Tex=tex;}); - -_ IM C shader_tex_frag[]=GRAPH_GLSL( - out vec4 Frag; - in vec3 Col; - in vec2 Tex; - uniform sampler2D buf0; - void main(){Frag=texture(buf0,Tex);}); - -_ U32 shader_tex; - -_ mat4 win_proj; -_ V shader_tex_init(V){ - shader_tex=graph_shader_create(shader_tex_vert,shader_tex_frag), - graph_shader_use(shader_tex); - graph_shader_setM4("proj",win_proj), - graph_shader_setI("buf0",0);} - -I main(I ac,C**av){(V)ac,(V)av;U32 cat; - graph_init(); - atexit(graph_deinit); - shader_tex_init(); - cat=graph_tex_create("res/tex/cat.jpg"); - WH(1,graph_before(),graph_events(); - glm_ortho(0,graph_win_w,0,graph_win_h,0,4,win_proj), - graph_shader_setM4("proj",win_proj), - graph_tex_use(cat,0), - graph_quad_xywh(200,200,200,200), - graph_after()); +X Scene scene_title; +I main(I ac,C**av){(V)ac,(V)av; + graph_init(),atexit(graph_deinit); + scene_run(&scene_title); R 0;} diff --git a/scene-title.c b/scene-title.c new file mode 100644 index 0000000..64429c5 --- /dev/null +++ b/scene-title.c @@ -0,0 +1,49 @@ +/*2d title screen*/ + +#include<cglm/affine.h> +#include<cglm/cglm.h> +#include"mino.h" +#include"graph.h" +#include"scene.h" + +_ mat4 win_proj; + +_ U32 shader_tex; +_ IM C shader_tex_vert[]=GRAPH_GLSL( + layout (location=0) in vec3 pos; + layout (location=1) in vec3 col; + layout (location=2) in vec2 tex; + out vec3 Col; + out vec2 Tex; + uniform mat4 proj; + uniform mat4 model; + void main(){gl_Position=proj*model*vec4(pos,1.0);Col=col;Tex=tex;}); +_ IM C shader_tex_frag[]=GRAPH_GLSL( + out vec4 Frag; + in vec3 Col; + in vec2 Tex; + uniform sampler2D buf; + void main(){Frag=texture(buf,Tex);}); +_ V shader_tex_init(V){ + shader_tex=graph_shader_create(shader_tex_vert,shader_tex_frag), + graph_shader_use(shader_tex), + graph_shader_setM4("proj",win_proj), + graph_shader_setI("buf",0);} + +_ U32 tex_cat; +_ V title_init(V){ + glm_ortho(0,graph_win_w,0,graph_win_h,0,4,win_proj), + shader_tex_init(); + tex_cat=graph_tex_create("res/tex/cat.jpg");} + +_ V title_loop(V){/*prelude*/graph_before(),graph_events(); + glm_ortho(0,graph_win_w,0,graph_win_h,0,4,win_proj), + /*interlude*/ + graph_shader_use(shader_tex),graph_shader_setM4("proj",win_proj), + graph_tex_use(tex_cat,0), + graph_quad_xywh(graph_win_w/2.0,graph_win_h/2.0,256,256), + /*postlude*/ + graph_after();} + +_ Scene*title_run(V){title_init();WH(1,title_loop());R 0;} +Scene scene_title={"title",title_run}; @@ -0,0 +1,4 @@ +#include<stdio.h> +#include"mino.h" +#include"scene.h" +V scene_run(Scene*x){WH(x,printf("Scene %s\n",x->n),x=x->f();)} |