diff --git a/Makefile b/Makefile index f2d2efa..ee40c04 100755 --- a/Makefile +++ b/Makefile @@ -73,7 +73,7 @@ SEM = 0.0.1 COM != git rev-parse --short HEAD VER = $(SEM)-$(COM) -COMPILER_FLAGS = $(includeflag) $(QFLAGS) -MD $(WARNING_FLAGS) -DCP_USE_DOUBLES=0 -DTINYSPLINE_FLOAT_PRECISION -DVER=\"$(VER)\" -DINFO=\"$(INFO)\" -c $< -o $@ +COMPILER_FLAGS = $(includeflag) $(QFLAGS) -MD $(WARNING_FLAGS) -DCP_USE_DOUBLES=0 -DTINYSPLINE_FLOAT_PRECISION -DDUK_USE_SYMBOL_BUILTIN -DVER=\"$(VER)\" -DINFO=\"$(INFO)\" -c $< -o $@ LIBPATH = -L$(BIN) diff --git a/source/engine/ffi.c b/source/engine/ffi.c index 31f080f..e2b3b09 100644 --- a/source/engine/ffi.c +++ b/source/engine/ffi.c @@ -701,6 +701,14 @@ duk_ret_t duk_cmd(duk_context *duk) { case 66: dukext2paths(duk_to_string(duk, 1)); return 1; + + case 67: + opengl_rendermode(LIT); + break; + + case 68: + opengl_rendermode(WIREFRAME); + break; } return 0; diff --git a/source/engine/openglrender.c b/source/engine/openglrender.c index 73b1d8e..1a52f44 100644 --- a/source/engine/openglrender.c +++ b/source/engine/openglrender.c @@ -12,9 +12,10 @@ #include "datastream.h" #include "nuke.h" -int renderMode = 0; +int renderMode = LIT; struct shader *spriteShader = NULL; +struct shader *wireframeShader = NULL; struct shader *animSpriteShader = NULL; static struct shader *textShader; @@ -64,6 +65,11 @@ void debug_draw_phys(int draw) { debugDrawPhysics = draw; } +void opengl_rendermode(enum RenderMode r) +{ + renderMode = r; +} + void openglInit() { if (!mainwin) { @@ -73,6 +79,7 @@ void openglInit() ////// MAKE SHADERS spriteShader = MakeShader("spritevert.glsl", "spritefrag.glsl"); + wireframeShader = MakeShader("spritevert.glsl", "spritewireframefrag.glsl"); animSpriteShader = MakeShader("animspritevert.glsl", "animspritefrag.glsl"); textShader = MakeShader("textvert.glsl", "textfrag.glsl"); @@ -117,8 +124,8 @@ void add_zoom(float val) { zoom = val; } void openglRender(struct window *window) { + glCullFace(GL_BACK); - glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //////////// 2D projection @@ -143,14 +150,25 @@ void openglRender(struct window *window) glBufferSubData(GL_UNIFORM_BUFFER, 0, 64, projection); + /* Game sprites */ + switch (renderMode) { + case LIT: + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + shader_use(spriteShader); + break; + + case WIREFRAME: + glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + shader_use(wireframeShader); + break; + }; + glEnable(GL_DEPTH_TEST); - ///// Sprites glDepthFunc(GL_LESS); - shader_use(spriteShader); sprite_draw_all(); - - + /* UI Elements & Debug elements */ + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glDisable(GL_DEPTH_TEST); //// DEBUG if (debugDrawPhysics) diff --git a/source/engine/openglrender.h b/source/engine/openglrender.h index 287cc17..151bafb 100644 --- a/source/engine/openglrender.h +++ b/source/engine/openglrender.h @@ -40,6 +40,7 @@ enum RenderMode { void openglInit(); void openglRender(struct window *window); +void opengl_rendermode(enum RenderMode r); void openglInit3d(struct window *window); void openglRender3d(struct window *window, struct mCamera *camera); diff --git a/source/shaders/spritefrag.glsl b/source/shaders/spritefrag.glsl index 8215e64..fc643db 100644 --- a/source/shaders/spritefrag.glsl +++ b/source/shaders/spritefrag.glsl @@ -11,4 +11,4 @@ void main() if (color.a <= 0.1f) discard; -} \ No newline at end of file +} diff --git a/source/shaders/spritewireframefrag.glsl b/source/shaders/spritewireframefrag.glsl new file mode 100644 index 0000000..39998ba --- /dev/null +++ b/source/shaders/spritewireframefrag.glsl @@ -0,0 +1,12 @@ +#version 330 core +in vec2 texcoords; +out vec4 color; + +uniform sampler2D image; +uniform vec3 spriteColor; + +void main() +{ + color = vec4(spriteColor, 1.f) * texture(image, texcoords); + color.a = 1.f; +}