polyadvent

A game engine from scratch in C
git clone git://jb55.com/polyadvent
Log | Files | Refs | README

commit 1f8ccbebbae181526906fac35a26ea66a60ed98e
parent a029a83bff3d9e9782b1788efc1c77204b6e3546
Author: William Casarin <bill@casarin.me>
Date:   Tue, 23 Jun 2015 02:18:45 -0700

cube finally working

Diffstat:
MMakefile | 4+++-
Metc/shaders/test.f.glsl | 2+-
Msrc/render.c | 10+++++-----
3 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/Makefile b/Makefile @@ -1,7 +1,9 @@ NAME ?= polyadvent BIN ?= $(NAME) PREFIX ?= /usr/local -CFLAGS = -ggdb -Wall -Wextra -Weverything -Werror -std=c99 -Wno-unused-function +CFLAGS = -ggdb -I src -Wall -Wextra -Weverything -Werror -std=c99 \ + -Wno-unused-function \ + -Wno-unused-variable LDFLAGS = -lSDL2 -lGL DEFS= -DGLFW_INCLUDE_NONE SRC=src diff --git a/etc/shaders/test.f.glsl b/etc/shaders/test.f.glsl @@ -3,5 +3,5 @@ varying float v_dot; void main() { vec4 color = vec4(0.4, 0.4, 0.8, 1.0); - gl_FragColor = vec4(color.xyz * v_dot, color.a); + gl_FragColor = vec4(color.xyz * v_dot, 1.0); } diff --git a/src/render.c b/src/render.c @@ -53,7 +53,7 @@ static const GLushort cube_indices[] = { void init_gl(struct test_resources * resources) { - //glEnable(GL_DEPTH_TEST); + glEnable(GL_DEPTH_TEST); SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); @@ -154,17 +154,17 @@ void render (struct test_resources * resources) { float fade_factor = resources->fade_factor; glClearColor( 0.0f, 0.0f, 0.0f, 1.0f ); //clear background screen to black - glClear( GL_COLOR_BUFFER_BIT ); + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); static float v3[] = { 1, 1, 0 }; - //v3[1] = fade_factor * 0.4f; + v3[1] = fade_factor * 1.4f; mat4_rotate(mvp, 0.004f, v3, mvp); mat4_multiply(camera, mvp, tmp_matrix); - recalc_normals(resources->uniforms.normal_matrix, mvp, normal); + recalc_normals(resources->uniforms.normal_matrix, tmp_matrix, normal); glUseProgram(resources->program); - glUniform3f(resources->uniforms.light_dir, -1, 1, -0.09f); + glUniform3f(resources->uniforms.light_dir, -1, 1, -0.099f); //glUniform1f(resources->uniforms.fade_factor, fade_factor); glUniformMatrix4fv(resources->uniforms.mvp, 1, 0, tmp_matrix);