polyadvent

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

commit 03d8407c08528c43092d06ab83694188fed0044b
parent bd0fb63172cd38751075475c135b488f176b66af
Author: William Casarin <jb55@jb55.com>
Date:   Sun,  4 Nov 2018 17:52:13 -0800

fix build on intel

Diffstat:
Metc/shaders/lighting.glsl | 6+++---
Metc/shaders/terrain.v.glsl | 4+---
Metc/shaders/test.f.glsl | 2--
Metc/shaders/uniforms.glsl | 4++--
Metc/shaders/vertex-color.glsl | 3+--
Msrc/render.c | 64+++++++++++++++++++++++++++++++++++++---------------------------
Msrc/shader.c | 4++++
Msrc/update.c | 2+-
8 files changed, 49 insertions(+), 40 deletions(-)

diff --git a/etc/shaders/lighting.glsl b/etc/shaders/lighting.glsl @@ -22,9 +22,9 @@ vec3 gamma_correct(vec3 color) { vec3 standard_light(vec3 color, vec4 position, vec4 normal) { // vec3 light_dir = vec3() const float pi = 3.14159265; - const float shiny = 12.0; + const float shiny = 14.0; const float exposure = 0.2; - float ambient_str = 0.25; + float ambient_str = 0.2; float spec_str = 0.8 * light_intensity; vec4 trans_normal = normal_matrix * normal; @@ -35,7 +35,7 @@ vec3 standard_light(vec3 color, vec4 position, vec4 normal) { // float light_intensity = light_intensity * 0.01; // too much ambient during daytime is making things look weird - // ambient_str =- light_intensity * ambient_str; + // ambient_str =- light_intensity * ambient_str * 0.05; vec3 ray = camera_position - position.xyz; vec3 view_dir = normalize(ray); diff --git a/etc/shaders/terrain.v.glsl b/etc/shaders/terrain.v.glsl @@ -1,7 +1,5 @@ #include profile -precision mediump float; - in vec3 position; in vec3 normal; @@ -42,6 +40,6 @@ void main() #include standard_vtxos.glsl - gl_Position = v4_pos; + gl_Position = mvp * v4_pos; data_out.position = gl_Position.xyz; } diff --git a/etc/shaders/test.f.glsl b/etc/shaders/test.f.glsl @@ -1,4 +1,3 @@ - #include profile out vec4 frag_color; @@ -16,7 +15,6 @@ uniform sampler2D shadow_map; #include fog.glsl void main() { - const float smoothness = 0.0; vec3 v_ray = camera_position - vertex.frag_pos; vec4 v4_pos = vec4(vertex.position, 1.0); vec4 v4_normal = vec4(vertex.normal, 1.0); diff --git a/etc/shaders/uniforms.glsl b/etc/shaders/uniforms.glsl @@ -1,10 +1,10 @@ -uniform bool diffuse_on; +// uniform bool diffuse_on; uniform bool fog_on; uniform float sky_intensity; uniform float light_intensity; uniform mat4 depth_mvp; -uniform mat4 depth_vp; +// uniform mat4 depth_vp; uniform mat4 mvp; uniform mat4 normal_matrix; uniform mat4 world; diff --git a/etc/shaders/vertex-color.glsl b/etc/shaders/vertex-color.glsl @@ -1,5 +1,5 @@ #include profile -precision mediump float; + in vec3 position; in vec3 normal; in vec3 color; @@ -10,7 +10,6 @@ out shader_data { #include uniforms.glsl - void main() { #include standard_vtxos.glsl diff --git a/src/render.c b/src/render.c @@ -70,8 +70,10 @@ init_gl(struct resources *resources, int width, int height) { glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 4); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); + check_gl(); + // Shaders ok = make_shader(GL_VERTEX_SHADER, SHADER("vertex-color.glsl"), &vertex); @@ -80,21 +82,25 @@ init_gl(struct resources *resources, int width, int height) { ok = make_shader(GL_VERTEX_SHADER, SHADER("terrain.v.glsl"), &terrain_vertex); assert(ok && "terrain vertex shader"); + check_gl(); - ok = make_shader(GL_GEOMETRY_SHADER, SHADER("terrain.g.glsl"), - &terrain_geom); - assert(ok && "terrain geometry shader"); + /* ok = make_shader(GL_GEOMETRY_SHADER, SHADER("terrain.g.glsl"), */ + /* &terrain_geom); */ + /* assert(ok && "terrain geometry shader"); */ - ok = make_shader(GL_TESS_CONTROL_SHADER, SHADER("terrain.tc.glsl"), - &terrain_tc); - assert(ok && "terrain tessellation control shader"); + /* ok = make_shader(GL_TESS_CONTROL_SHADER, SHADER("terrain.tc.glsl"), */ + /* &terrain_tc); */ + /* assert(ok && "terrain tessellation control shader"); */ + /* check_gl(); */ - ok = make_shader(GL_TESS_EVALUATION_SHADER, SHADER("terrain.te.glsl"), - &terrain_teval); - assert(ok && "terrain tessellation eval shader"); + /* ok = make_shader(GL_TESS_EVALUATION_SHADER, SHADER("terrain.te.glsl"), */ + /* &terrain_teval); */ + /* assert(ok && "terrain tessellation eval shader"); */ + /* check_gl(); */ ok = make_shader(GL_FRAGMENT_SHADER, SHADER("test.f.glsl"), &fragment); assert(ok && "default fragment shader"); + check_gl(); // camera mat4_perspective(90 /* fov */, @@ -111,11 +117,12 @@ init_gl(struct resources *resources, int width, int height) { /* struct shader *terrain_shaders[] = */ /* { &terrain_vertex, &fragment, &terrain_tc, &terrain_teval }; */ + /* struct shader *terrain_shaders[] = */ + /* { &terrain_vertex, &fragment, &terrain_geom }; */ + struct shader *terrain_shaders[] = - { &terrain_vertex, &fragment, &terrain_geom }; + { &terrain_vertex, &fragment }; - /* struct shader *terrain_shaders[] = */ - /* { &terrain_vertex, &fragment }; */ ok = make_program_from_shaders(terrain_shaders, ARRAY_SIZE(terrain_shaders), &resources->programs[TERRAIN_PROGRAM]); @@ -140,9 +147,9 @@ init_gl(struct resources *resources, int width, int height) { glGetUniformLocation(handle, "camera_position"); check_gl(); - resources->uniforms.depth_vp = - glGetUniformLocation(handle, "depth_vp"); - check_gl(); + /* resources->uniforms.depth_vp = */ + /* glGetUniformLocation(handle, "depth_vp"); */ + /* check_gl(); */ resources->uniforms.depth_mvp = glGetUniformLocation(handle, "depth_mvp"); @@ -176,16 +183,16 @@ init_gl(struct resources *resources, int width, int height) { glGetUniformLocation(handle, "fog_on"); check_gl(); - resources->uniforms.diffuse_on = - glGetUniformLocation(handle, "diffuse_on"); - check_gl(); + /* resources->uniforms.diffuse_on = */ + /* glGetUniformLocation(handle, "diffuse_on"); */ + /* check_gl(); */ resources->uniforms.mvp = glGetUniformLocation(handle, "mvp"); check_gl(); - resources->uniforms.model_view = - glGetUniformLocation(handle, "model_view"); + /* resources->uniforms.model_view = */ + /* glGetUniformLocation(handle, "model_view"); */ resources->uniforms.normal_matrix = glGetUniformLocation(handle, "normal_matrix"); @@ -295,8 +302,11 @@ void render (struct game *game, struct render_config *config) { camera[M_Z]); glUniform1i(res->uniforms.fog_on, res->fog_on); - glUniform1i(res->uniforms.diffuse_on, res->diffuse_on); + check_gl(); + /* glUniform1i(res->uniforms.diffuse_on, res->diffuse_on); */ + /* check_gl(); */ glUniform3f(res->uniforms.light_dir, light[0], light[1], light[2]); + check_gl(); glUniform1f(res->uniforms.light_intensity, res->light_intensity); check_gl(); /* glUniform1f(res->uniforms.time, res->time); */ @@ -320,10 +330,10 @@ void render (struct game *game, struct render_config *config) { check_gl(); glUniformMatrix4fv(res->uniforms.depth_mvp, 1, 0, depth_mvp); check_gl(); - glUniformMatrix4fv(res->uniforms.depth_vp, 1, 0, config->depth_vp); - check_gl(); - glUniformMatrix4fv(res->uniforms.model_view, 1, 0, model_view); - check_gl(); + /* glUniformMatrix4fv(res->uniforms.depth_vp, 1, 0, config->depth_vp); */ + /* check_gl(); */ + /* glUniformMatrix4fv(res->uniforms.model_view, 1, 0, model_view); */ + /* check_gl(); */ glUniformMatrix4fv(res->uniforms.world, 1, 0, entity->node.mat); check_gl(); diff --git a/src/shader.c b/src/shader.c @@ -4,6 +4,7 @@ #include <assert.h> #include "file.h" +#include "util.h" #include "gl.h" #include "debug.h" #include "shader.h" @@ -222,6 +223,7 @@ make_program_from_shaders(struct shader **shaders, int n_shaders, struct gpu_pro // TODO: relax these constraints program->handle = glCreateProgram(); + check_gl(); program->n_shaders = n_shaders; assert(n_shaders <= MAX_SHADERS); @@ -234,9 +236,11 @@ make_program_from_shaders(struct shader **shaders, int n_shaders, struct gpu_pro /* shader->includes[j]); */ /* } */ glAttachShader(program->handle, shader->handle); + check_gl(); } glLinkProgram(program->handle); + check_gl(); glGetProgramiv(program->handle, GL_LINK_STATUS, &program_ok); diff --git a/src/update.c b/src/update.c @@ -219,7 +219,7 @@ void resize_fbos(struct entity *player, struct fbo *shadow_buffer, } // TODO: compute better bounds based - const float factor = 50.0; + const float factor = 80.0; float left = player->model.geom.min[0] - factor; float right = player->model.geom.max[0] + factor; float bottom = player->model.geom.min[1] - factor;