From 7c1edef3ac501d40e3de495b9434df71f535e9bc Mon Sep 17 00:00:00 2001 From: Tomasz Kramkowski Date: Fri, 19 Oct 2018 23:22:07 +0300 Subject: Allow multiple shaders while reducing duplication This change also stops using bie as eventually it will be replaced with a more sophisticated asset handling system which will also allow custom shaders. --- faqe.c | 38 ++++++++++---------------------------- 1 file changed, 10 insertions(+), 28 deletions(-) (limited to 'faqe.c') diff --git a/faqe.c b/faqe.c index 7f4803c..afb8bb4 100644 --- a/faqe.c +++ b/faqe.c @@ -5,7 +5,6 @@ #include #include -#include "assets.h" #include "camera.h" #include "eprintf.h" #include "gl.h" @@ -49,10 +48,6 @@ int main(int argc, char **argv) bool running = true; SDL_Window *win; SDL_GLContext *glc; - GLuint prog; - struct { - GLint model, view, proj, tex, light; - } uni; struct model mdl; struct camera cam = { .pos = { 0.0, 0.0, 3.0 }, .yaw = -PI/2 }; struct { @@ -88,24 +83,11 @@ int main(int argc, char **argv) loadmodel(&mdl, "assets/utah.fmd"); - prog = glprog_load((struct shdrdat []){ - { GL_VERTEX_SHADER, vert_glsl.data, vert_glsl.size }, - { GL_FRAGMENT_SHADER, frag_glsl.data, frag_glsl.size }, - { 0 }, - }, - (struct unidat []){ - { "model", &uni.model }, - { "view", &uni.view }, - { "proj", &uni.proj }, - { "tex", &uni.tex }, - { "light", &uni.light }, - { 0 }, - }); - - gl_uni_set1i(uni.tex, 0); - - gl_prog_use(prog); - viewport(uni.proj, WIDTH, HEIGHT); + glprog_init(); + + gl_prog_use(prog.main.prog); + viewport(prog.main.uni.proj, WIDTH, HEIGHT); + gl_uni_set1i(prog.main.tex.tex, 0); gl_enable(GL_DEPTH_TEST); gl_enable(GL_FRAMEBUFFER_SRGB); @@ -148,7 +130,7 @@ int main(int argc, char **argv) case SDL_WINDOWEVENT: switch (ev.window.event) { case SDL_WINDOWEVENT_SIZE_CHANGED: - viewport(uni.proj, + viewport(prog.main.uni.proj, ev.window.data1, ev.window.data2); } @@ -180,10 +162,10 @@ int main(int argc, char **argv) gl_clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); mat4x4_identity(model); - gl_prog_use(prog); - gl_uni_setm4fv(uni.view, 1, GL_FALSE, (GLfloat *)view); - gl_uni_setm4fv(uni.model, 1, GL_FALSE, (GLfloat *)model); - gl_uni_set3fv(uni.light, 1, lipos); + gl_prog_use(prog.main.prog); + gl_uni_setm4fv(prog.main.uni.view, 1, GL_FALSE, (GLfloat *)view); + gl_uni_setm4fv(prog.main.uni.model, 1, GL_FALSE, (GLfloat *)model); + gl_uni_set3fv(prog.main.uni.light, 1, lipos); model_render(&mdl); gl_va_bind(0); -- cgit v1.2.3-54-g00ecf