From 22684f22d59d0e902969fc5ac287ebd5ccf98df8 Mon Sep 17 00:00:00 2001 From: Shariq Shah Date: Sun, 26 Feb 2017 15:43:17 +0500 Subject: [PATCH] Fixed issues with opengl context version and minor bug with blinn-phong uniform bug --- assets/shaders/blinn_phong.frag | 1 - assets/shaders/commonVert.glsl | 10 +++++----- orgfile.org | 7 +++++-- src/material.c | 8 ++++---- src/platform.c | 7 +++++-- src/renderer.c | 2 +- src/texture.c | 6 ++++-- 7 files changed, 24 insertions(+), 17 deletions(-) diff --git a/assets/shaders/blinn_phong.frag b/assets/shaders/blinn_phong.frag index 8a1f37a..a60655a 100644 --- a/assets/shaders/blinn_phong.frag +++ b/assets/shaders/blinn_phong.frag @@ -36,7 +36,6 @@ vec3 calc_point_light(in Light light) vec3 specular_comp = vec3(0.0); vec3 light_direction = vertex - light.position; float dist = abs(length(light_direction)); - if(dist <= light.radius) { light_direction = normalize(light_direction); diff --git a/assets/shaders/commonVert.glsl b/assets/shaders/commonVert.glsl index 87a0b41..454adca 100644 --- a/assets/shaders/commonVert.glsl +++ b/assets/shaders/commonVert.glsl @@ -7,13 +7,13 @@ in vec2 vUV; out vec2 uv; out vec3 normal; out vec3 vertex; -out vec3 vertCamSpace; -out vec4 vertLightSpace; +// out vec3 vertCamSpace; +// out vec4 vertLightSpace; // Common uniforms uniform mat4 model_mat; uniform mat4 inv_model_mat; -uniform mat4 view_mat; +// uniform mat4 view_mat; uniform mat4 mvp; uniform mat4 lightVPMat; @@ -28,6 +28,6 @@ void setOutputs() //Normal and vertex sent to the fragment shader should be in the same space! normal = vec4(transpose(inv_model_mat) * vec4(vNormal, 0.0)).xyz; vertex = vec4(model_mat * vec4(vPosition, 1.0)).xyz; - vertCamSpace = vec4(view_mat * vec4(vPosition, 1.0)).xyz; - vertLightSpace = vec4((lightVPMat * model_mat) * vec4(vPosition, 1.0)); + // vertCamSpace = vec4(view_mat * vec4(vPosition, 1.0)).xyz; + // vertLightSpace = vec4((lightVPMat * model_mat) * vec4(vPosition, 1.0)); } diff --git a/orgfile.org b/orgfile.org index 377b09d..38468fd 100644 --- a/orgfile.org +++ b/orgfile.org @@ -74,7 +74,9 @@ All the code in this repository is under GPLv3, see LICENSE for more information ** TODO Lights! ** DONE Fix problems with texture units - State "DONE" from "TODO" [2016-05-30 Mon 00:57] -** TODO Draw light volumes +** CANCELED Draw light volumes +- State "CANCELED" from "TODO" [2017-02-26 Sun 15:39] \\ + Deferred rendering on hold for now. ** TODO Fix problems with frustrum culling - Recalculate bounding boxes for rotated meshes? ** TODO 2d drawing routines @@ -87,7 +89,8 @@ All the code in this repository is under GPLv3, see LICENSE for more information ** TODO Variant type ** TODO Event Subsystem ** TODO Fix mouse bugs -** TODO Fix issues with opengl context showing 2.1 only +** DONE Fix issues with opengl context showing 2.1 only +- State "DONE" from "TODO" [2017-02-26 Sun 15:39] ** TODO Improve this readme ** TODO ??? ** TODO Profit! diff --git a/src/material.c b/src/material.c index b04cb12..ff723f8 100644 --- a/src/material.c +++ b/src/material.c @@ -100,10 +100,10 @@ void material_init(void) uniform->type = UT_MAT4; uniform->location = shader_get_uniform_location(blinn_phong_mat->shader, uniform->name); - uniform = array_grow(blinn_phong_mat->pipeline_params, struct Uniform); - uniform->name = str_new("view_mat"); - uniform->type = UT_MAT4; - uniform->location = shader_get_uniform_location(blinn_phong_mat->shader, uniform->name); + /* uniform = array_grow(blinn_phong_mat->pipeline_params, struct Uniform); */ + /* uniform->name = str_new("view_mat"); */ + /* uniform->type = UT_MAT4; */ + /* uniform->location = shader_get_uniform_location(blinn_phong_mat->shader, uniform->name); */ uniform = array_grow(blinn_phong_mat->pipeline_params, struct Uniform); uniform->name = str_new("inv_model_mat"); diff --git a/src/platform.c b/src/platform.c index cb64e11..0efc2fe 100644 --- a/src/platform.c +++ b/src/platform.c @@ -44,8 +44,11 @@ struct Window* window_create(const char* title, int width, int height) SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 4); - //SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY); + SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 24); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); + //SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY); #ifdef GL_DEBUG_CONTEXT SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG); #endif diff --git a/src/renderer.c b/src/renderer.c index 7be360f..5c3acfa 100644 --- a/src/renderer.c +++ b/src/renderer.c @@ -28,7 +28,7 @@ void renderer_init(void) { glClearColor(0.3f, 0.6f, 0.9f, 1.0f); glEnable(GL_DEPTH_TEST); - glEnable(GL_TEXTURE_2D); + /* glEnable(GL_TEXTURE_2D); */ glEnable(GL_CULL_FACE); glCullFace(GL_BACK); platform_windowresize_callback_set(on_framebuffer_size_change); diff --git a/src/texture.c b/src/texture.c index c64332e..515bf14 100644 --- a/src/texture.c +++ b/src/texture.c @@ -299,10 +299,12 @@ void texture_set_param(int index, int parameter, int value) return; GLint curr_texture = 0; - glGetIntegerv(GL_TEXTURE_2D, &curr_texture); + glGetIntegerv(GL_TEXTURE_BINDING_2D, &curr_texture); + renderer_check_glerror("texture:set_param:glGetIntegerv"); glBindTexture(GL_TEXTURE_2D, texture->handle); + renderer_check_glerror("texture:set_param:glBindTexture"); glTexParameteri(GL_TEXTURE_2D, parameter, value); - renderer_check_glerror("texture:set_param"); + renderer_check_glerror("texture:set_param:glTexParameteri"); if(curr_texture != 0) glBindTexture(GL_TEXTURE_2D, curr_texture); }