aboutsummaryrefslogtreecommitdiffstats
path: root/faqe.c
diff options
context:
space:
mode:
authorTomasz Kramkowski <tk@the-tk.com>2018-10-19 23:22:07 +0300
committerTomasz Kramkowski <tk@the-tk.com>2018-10-19 23:30:23 +0300
commit7c1edef3ac501d40e3de495b9434df71f535e9bc (patch)
treefd7f4264bdf5c30f7182a147ed9e6c7935c69bf2 /faqe.c
parent91b543a29cb8852251908a49cd120a6f7d9f2f11 (diff)
downloadfaqe-7c1edef3ac501d40e3de495b9434df71f535e9bc.tar.gz
faqe-7c1edef3ac501d40e3de495b9434df71f535e9bc.tar.xz
faqe-7c1edef3ac501d40e3de495b9434df71f535e9bc.zip
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.
Diffstat (limited to 'faqe.c')
-rw-r--r--faqe.c38
1 files changed, 10 insertions, 28 deletions
diff --git a/faqe.c b/faqe.c
index 7f4803c..afb8bb4 100644
--- a/faqe.c
+++ b/faqe.c
@@ -5,7 +5,6 @@
#include <SDL.h>
#include <stdbool.h>
-#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);