Embeddable shaders
This commit is contained in:
parent
6025a5a614
commit
39dbf40cd3
2
.gitignore
vendored
2
.gitignore
vendored
@ -2,3 +2,5 @@
|
||||
compile_commands.json
|
||||
zoomer
|
||||
zoomer.o
|
||||
fshader.h
|
||||
vshader.h
|
||||
|
23
Makefile
23
Makefile
@ -1,32 +1,39 @@
|
||||
.PHONY: all clean run
|
||||
VERSION = 0.0.1
|
||||
.PHONY: all clean run bear build
|
||||
VERSION = 0.0.2
|
||||
|
||||
PREFIX=/usr/local
|
||||
|
||||
LIBS = sdl2 glew
|
||||
CMACRO = -DVERSION=\"$(VERSION)\"
|
||||
CMACRO = -DVERSION=\"$(VERSION)\" $(if $(EMBED_SHADER),-DEMBED_SHADER,)
|
||||
|
||||
CC = gcc
|
||||
CFLAGS = -g -Wall -Wextra -pedantic $(shell pkg-config $(LIBS) --cflags) $(CMACRO)
|
||||
LDFLAGS = $(shell pkg-config $(LIBS) --libs) -lm
|
||||
|
||||
all: zoomer
|
||||
all: zoomer
|
||||
|
||||
zoomer: zoomer.o
|
||||
zoomer: $(if $(EMBED_SHADER),fshader.h vshader.h,) zoomer.o
|
||||
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
|
||||
|
||||
%.o: %.c
|
||||
$(CC) $(CFLAGS) -c -o $@ $<
|
||||
|
||||
%.h: %.glsl
|
||||
xxd -i $< $@
|
||||
|
||||
clean:
|
||||
rm -f fshader.h vshader.h
|
||||
rm -f *.o
|
||||
rm -f zoomer
|
||||
|
||||
install: zoomer
|
||||
install -Dm755 $< $(DESTDIR)$(PREFIX)/bin/$<
|
||||
install: build
|
||||
install -Dm755 zoomer $(DESTDIR)$(PREFIX)/bin/zoomer
|
||||
|
||||
bear: clean
|
||||
bear -- make
|
||||
|
||||
run: zoomer
|
||||
build:
|
||||
EMBED_SHADER=y $(MAKE) zoomer
|
||||
|
||||
run: zoomer
|
||||
./$<
|
||||
|
10
tutils.h
10
tutils.h
@ -9,16 +9,16 @@ const char* pullArg(int *argc, char** argv[]){
|
||||
return *argv[0]++;
|
||||
}
|
||||
|
||||
const char *readFile(const char* filename){
|
||||
const char* readFile(const char* filename, long *size){
|
||||
FILE *fd = fopen(filename, "r");
|
||||
|
||||
fseek(fd, 0, SEEK_END);
|
||||
long size = ftell(fd);
|
||||
*size = ftell(fd);
|
||||
rewind(fd);
|
||||
|
||||
char* ret = malloc(size+1);
|
||||
fread(ret, sizeof(char), size, fd);
|
||||
ret[size] = 0;
|
||||
char* ret = malloc(*size+1);
|
||||
fread(ret, sizeof(char), *size, fd);
|
||||
ret[*size] = 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
17
zoomer.c
17
zoomer.c
@ -68,11 +68,20 @@ int main(int argc, char *argv[])
|
||||
|
||||
GLuint vshader = glCreateShader(GL_VERTEX_SHADER),
|
||||
fshader = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
const char *vshadersrc = readFile("vshader.glsl"),
|
||||
*fshadersrc = readFile("fshader.glsl");
|
||||
|
||||
glShaderSource(vshader, 1, &vshadersrc, NULL);
|
||||
glShaderSource(fshader, 1, &fshadersrc, NULL);
|
||||
#ifndef EMBED_SHADER
|
||||
long vshader_glsl_len, fshader_glsl_len;
|
||||
const char *vshadersrc = readFile("vshader.glsl", &vshader_glsl_len),
|
||||
*fshadersrc = readFile("fshader.glsl", &fshader_glsl_len);
|
||||
#else
|
||||
#include "vshader.h"
|
||||
#include "fshader.h"
|
||||
const char *vshadersrc = vshader_glsl,
|
||||
*fshadersrc = fshader_glsl;
|
||||
#endif
|
||||
|
||||
glShaderSource(vshader, 1, &vshadersrc, (int *)&vshader_glsl_len);
|
||||
glShaderSource(fshader, 1, &fshadersrc, (int *)&fshader_glsl_len);
|
||||
|
||||
glCompileShader(vshader);
|
||||
glCompileShader(fshader);
|
||||
|
Loading…
Reference in New Issue
Block a user