]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
Something fixed
authordrumsetmonkey <abelleisle@roadrunner.com>
Mon, 23 May 2016 12:40:53 +0000 (08:40 -0400)
committerdrumsetmonkey <abelleisle@roadrunner.com>
Mon, 23 May 2016 12:40:53 +0000 (08:40 -0400)
brice.dat
main.cpp
shaders/world.frag
shaders/world.vert
src/inventory.cpp
src/ui.cpp

index ea71945339f7a7cd6d35324a11df49578bb93bfc..61d57c2785952fa6cb22f35f6db947ff5ddf91d2 100644 (file)
--- a/brice.dat
+++ b/brice.dat
@@ -1,5 +1,5 @@
 2
-canSprint
-0
 canJump
 0
+canSprint
+0
index 2f094dc1d6573971f80f8dbfcdc26edb3197b6f4..07774f42d33970f32e92080e1d114d7af3603e86 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -208,7 +208,7 @@ int main(int argc, char *argv[]){
        worldShader_uniform_transform =                 get_uniform(worldShader, "transform");
        worldShader_uniform_ortho =                     get_uniform(worldShader, "ortho");
        worldShader_uniform_color =                     get_uniform(worldShader, "tex_color");
-       worldShader_uniform_ambient =                   get_uniform(worldShader, "ambient");
+       worldShader_uniform_ambient =                   get_uniform(worldShader, "ambientLight");
        worldShader_uniform_light =                     get_uniform(worldShader, "light");
        worldShader_uniform_light_color =               get_uniform(worldShader, "lightColor");
        worldShader_uniform_light_impact =              get_uniform(worldShader, "lightImpact");
@@ -374,7 +374,7 @@ void render() {
        glUniformMatrix4fv(worldShader_uniform_transform, 1, GL_FALSE, glm::value_ptr(glm::mat4(1.0f)));
        
        glUniform4f(worldShader_uniform_color, 1.0, 1.0, 1.0, 1.0);
-       glUniform1f(worldShader_uniform_ambient, 1.0);
+       glUniform4f(worldShader_uniform_ambient, 1.0, 1.0, 1.0, 1.0);
        glUniform1i(worldShader_uniform_light_amt, 0);
        glUniform1f(worldShader_uniform_light_impact, 1.0);
        /**************************
index d50e01dbc39b7b041014f61e4d48d8ed46df559c..31777955ee8b96a1ead09712a8991db6a20eae30 100644 (file)
@@ -3,6 +3,7 @@ uniform sampler2D normalTex;
 
 varying vec2 texCoord;
 varying vec4 color;
+varying vec3 fragCoord;
 
 uniform vec4 ambientLight;
 uniform vec4 light[128];
@@ -10,16 +11,26 @@ uniform vec4 lightColor[128];
 uniform float lightImpact;
 uniform int lightSize;
 
+float b = .0005f;
+float minLight = .05f;
+float radius = sqrt(1.0f / (b * minLight));
+
 void main()
 {
-
        vec4 pixTex = texture2D(texture, vec2(texCoord.x, 1-texCoord.y));
-    if (pixTex.a < 0.1) 
+    if (pixTex.a < 0.1f
                discard;
-    
-       if (lightSize > 0) {
-
+       vec4 shadeColor = vec4(0.0f, 0.0f, 0.0f, 0.0f);
+       for (int i = 0; i < lightSize; i++) {
+               vec2 loc = light[i].xy;
+               float dist = length(loc - fragCoord.xy);
+               float attenuation = clamp(1.0f - dist*dist/(radius*radius), 0.0f, 1.0f);
+               attenuation *= attenuation;
+               
+               shadeColor += vec4(attenuation, attenuation, attenuation, 1.0f) * vec4(lightColor[i]);          
        }
-       
-       gl_FragColor = pixTex * color * pixTex.a;
+       shadeColor += ambientLight;     
+
+       gl_FragColor = pixTex * color * shadeColor;
 }
index 10869d68d2b9aa75528f1ef6383fc0f86e742fb8..df814e6ce3f0fd4a31c0eb08c3ddd3af4f5f2bbc 100644 (file)
@@ -7,9 +7,11 @@ uniform mat4 transform;
 
 varying vec2 texCoord;
 varying vec4 color;
+varying vec3 fragCoord;
 
 void main(){
        color = tex_color;
     texCoord = tex_coord;
     gl_Position = ortho * transform * vec4(coord2d.xyz, 1.0);
+       fragCoord = vec3(gl_Position.xyz);
 }
index a7c19dac2a99b021ca7ae09cf72f68f3a4b058d1..e235f51bb48c784e86a438cf5afafbb3ee197766 100644 (file)
@@ -462,7 +462,7 @@ void Inventory::draw(void) {
             glUseProgram(textShader);
                        glBindTexture(GL_TEXTURE_2D, Texture::genColor(Color(0.0f, 0.0f, 0.0f, t >= 0 ? 255 * t : 0)));
             drawRect(vec2(r.end.x-(itemWide/2),                 r.end.y-(itemWide/2)),
-                     vec2(r.end.x-(itemWide/2)+itemWide,r.end.y-(itemWide/2)+itemWide), -6.1);
+                     vec2(r.end.x-(itemWide/2)+itemWide,r.end.y-(itemWide/2)+itemWide), -6.0);
 
                        if (!Items.empty() && a < numSlot && Items[a].second) {
                                glBindTexture(GL_TEXTURE_2D, Items[a].first->tex->image[0]);//itemtex[items[a].id]);
index 6eca97d5bed6a5761fab68edbb8353c879f29e96..7ae444cb74b3f78c5811881aa783d8be22e87c04 100644 (file)
@@ -1345,6 +1345,9 @@ EXIT:
                                case SDLK_F3:
                                        debug ^= true;
                                        break;
+                               case SDLK_BACKSLASH:
+                                       dialogBoxExists = false;
+                                       break;
                                case SDLK_x:
                                        m = currentWorld->getNearMob(*player);
                                        if (m != nullptr)