]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
Lighting!
authordrumsetmonkey <abelleisle@roadrunner.com>
Wed, 8 Jun 2016 12:41:44 +0000 (08:41 -0400)
committerdrumsetmonkey <abelleisle@roadrunner.com>
Wed, 8 Jun 2016 12:41:44 +0000 (08:41 -0400)
24 files changed:
assets/cat.png
assets/style/classic/bg/bgFarMountain.png
assets/style/classic/bg/bgn.png
assets/style/classic/bg/forestTileBack.png
assets/style/classic/bg/forestTileFar.png
assets/style/classic/bg/forestTileFront.png
assets/style/classic/bg/forestTileMid.png
brice.dat
config/items.xml
frig.frag
include/common.hpp
include/entities.hpp
include/inventory.hpp
include/texture.hpp
include/world.hpp
main.cpp
shaders/world.frag
shaders/world.vert
src/inventory.cpp
src/items.cpp
src/mob.cpp
src/ui.cpp
src/world.cpp
xml/playerSpawnHill1.xml

index 56821dd80d28e122ad0db6f47e1feffdb5605f08..c5b83c7faae25a94b8dcfaa0d496ab7b81054068 100644 (file)
Binary files a/assets/cat.png and b/assets/cat.png differ
index eb703bbe8200635e8c895d12739325b291cb2137..dc4d6825952d41400f52d025025a0ff0b4ccdd35 100644 (file)
Binary files a/assets/style/classic/bg/bgFarMountain.png and b/assets/style/classic/bg/bgFarMountain.png differ
index 2aa3995a249ed59b3c012d0f72aec3e2cf3ca457..1ac312743bd76f0000e1f13a48747d1155c4298b 100644 (file)
Binary files a/assets/style/classic/bg/bgn.png and b/assets/style/classic/bg/bgn.png differ
index 0ea602268981b624d6837f774205bc9e16f9807f..f43346ce9eb24206c8646ce63bc026020668433a 100644 (file)
Binary files a/assets/style/classic/bg/forestTileBack.png and b/assets/style/classic/bg/forestTileBack.png differ
index 241e47962aedcd5243c310d80837ef12d0d139d2..b7cb14052a6175a5e2ea13d86093611bdf9c86e4 100644 (file)
Binary files a/assets/style/classic/bg/forestTileFar.png and b/assets/style/classic/bg/forestTileFar.png differ
index e54f6312edc969adf7bd6ea94fcf8b449379eef8..d81b2c77aa1b2d56f35a02c1500cea558829d695 100644 (file)
Binary files a/assets/style/classic/bg/forestTileFront.png and b/assets/style/classic/bg/forestTileFront.png differ
index b23afd2df0a36c8e34851cb8ada73c0da542e2d0..6c4c5972e8d04b4b5f1b373e3dccd4c188ec0df4 100644 (file)
Binary files a/assets/style/classic/bg/forestTileMid.png and b/assets/style/classic/bg/forestTileMid.png differ
index bda8adcb6642decd7a089554d88b1583f814346b..4bfeac60c203b4b22f8a89cba605f469d3bf47d2 100644 (file)
--- a/brice.dat
+++ b/brice.dat
@@ -1,5 +1,5 @@
 2
-canSprint
-1
 canJump
 1
+canSprint
+1
index 119284235bc93296d9cce21ed6fe1c06928ff755..0abd40d7a75b0acc831c4c43bf42432d0b918969 100644 (file)
 <item name="Flashlight"     type="Tool"         value="1"  maxStackSize="1"   width="4"  height="8"  sprite="assets/items/flashlight_off.png" />
 <item name="Fried Chicken"  type="Cooked Food"  value="10" maxStackSize="6" sprite="assets/items/FOOD_CHICKEN_FRIED.png" />
 
+<!--###########-->
 <!-- NEW ITEMS -->
+<!--##########-->
+
+<!-- WEAPONS -->
 <item name="Wood Sword"     type="Sword"    damage="3"  maxStackSize="1"    sprite="assets/items/SWORD_WOOD.png" />
 <item name="Hunters Bow"    type="Bow"      damage="2"  maxStackSize="1"    sprite="assets/items/bow.png"/>
 <item name="Crude Arrow"    type="Arrow"    damage="1"  maxStackSize="99"   sprite="assets/items/arrow_crude.png"/>
+
+<!-- UTILITIES -->
+<item name="Rusty Lantern"     type="Light"                     radius="150" color="255|255|255" sprite="assets/items/rusty_lantern.png"/>
+<item name="Mossy Torch"       type="Light" fire="true" radius="150" color="245|220|200" sprite="assets/items/basic_torch.png"/>
index 8761efef306b34313e6350f5054e189a11594344..b291ddfefc2e647e20a81b7364ac290816a0339b 100644 (file)
--- a/frig.frag
+++ b/frig.frag
@@ -31,4 +31,4 @@ void main(){
 
        color += vec4(amb,amb,amb,1.0f+amb);
        gl_FragColor = tex * vec4(color)*tex.a;
-}
\ No newline at end of file
+}
index 934ede5f91222037f8e2d3a3d60a7a4911ac8703..1ef8b8a083c88a9b383308a02e09d5a31555902e 100644 (file)
@@ -238,6 +238,7 @@ extern GLint worldShader_uniform_light_color;
 extern GLint worldShader_uniform_light_impact;
 extern GLint worldShader_uniform_light_amt;
 
+extern Color ambient;
 /**
  *     Prints a formatted debug message to the console, along with the callee's file and line
  *     number.
index ca4ef2b7a7473403867d5f628db5e1562fa88b82..d2185c4cd1582cc2c2760818719e10ba569344c8 100644 (file)
@@ -400,7 +400,8 @@ public:
        float fireFlicker;
        vec2 fireLoc;
 
-       Light(vec2 l, Color c, float r){
+       Light(vec2 l, float r, Color c)
+       {
                loc = l;
                color = c;
                radius = r;
@@ -411,7 +412,14 @@ public:
                flame = false;
        }
 
-       void makeFlame(void){
+       void follow(Entity *f)
+       {
+               following = f;
+               belongsTo = true;
+       }
+
+       void makeFlame(void)
+       {
                flame = true;
        }
 };
index 1431f42a903a8e60b7b55995b106013873c1b1ee..a85e537e93aed19937a480f0a835254f4af7632d 100644 (file)
@@ -185,6 +185,18 @@ public:
        Food* clone();
 };
 
+class ItemLight : public Item {
+private:
+       // the color of the light
+       Color color;
+public:
+       // turn on/off the light
+       // TODO
+       int useItem();
+
+       ItemLight* clone();
+};
+
 /**
  *     Currency class. Well, it's used for currency
  */
index df2a83c38a553bc879e9b2359228981eb6b469e0..95bd73b190991a49de6df145584fc216967e4038 100644 (file)
@@ -76,6 +76,9 @@ public:
 
                return textures[index].second;
        }
+       const dim2 getTextureDim(void) {
+               return Texture::imageDim((*position).second);
+       }
 };
 
 /**
index ce50244175c2bd30b98cbd1decc39df6e77b2d66..ecfa14f092bf540ea9b5c24947fa3868add16f81 100644 (file)
@@ -459,7 +459,7 @@ public:
        void addHill(ivec2 peak, unsigned int width);
 
        // functions to add entities to the world
-       void addLight(vec2 xy, Color color);
+       void addLight(vec2 xy, float radius, Color color);
 
        void addMerchant(float x, float y, bool housed);
 
index 66cf12c4c5609cb57ab3ea142880945b64c1a79f..8c41258ec28ac6a468209372e545dd42acd02280 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -81,6 +81,9 @@ GLint worldShader_uniform_light_color;
 GLint worldShader_uniform_light_impact;
 GLint worldShader_uniform_light_amt;
 
+// the ambient light of the current world
+Color ambient;
+
 // keeps a simple palette of colors for single-color draws
 GLuint colorIndex;
 
@@ -365,6 +368,7 @@ void render() {
        glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
        // TODO add depth
     glEnable(GL_DEPTH_TEST);
+       //glEnable(GL_CULL_FACE);
 
        glUseProgram(textShader);
        glUniformMatrix4fv(textShader_uniform_transform, 1, GL_FALSE, glm::value_ptr(ortho));
@@ -374,9 +378,15 @@ 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);
-       glUniform4f(worldShader_uniform_ambient, 1.0, 1.0, 1.0, 1.0);
-       glUniform1i(worldShader_uniform_light_amt, 0);
+       glUniform4f(worldShader_uniform_ambient, ambient.red, ambient.green, ambient.blue, 1.0);
        glUniform1f(worldShader_uniform_light_impact, 1.0);
+       
+       /*static GLfloat l[]  = {460.0, 100.0, 0.0, 300.0};
+       static GLfloat lc[] = {1.0, 1.0, 1.0, 1.0};
+       glUniform4fv(worldShader_uniform_light, 1, l); 
+       glUniform4fv(worldShader_uniform_light_color, 1, lc);
+       glUniform1i(worldShader_uniform_light_amt, 1);
+       */
        /**************************
        **** RENDER STUFF HERE ****
        **************************/
@@ -462,44 +472,44 @@ void render() {
        if (currentMenu)
                ui::menu::draw();
 
-               glUseProgram(textShader);
-               glActiveTexture(GL_TEXTURE0);
-               glBindTexture(GL_TEXTURE_2D, mouseTex);
-               glUniform1i(textShader_uniform_texture, 0);
+       glUseProgram(textShader);
+       glActiveTexture(GL_TEXTURE0);
+       glBindTexture(GL_TEXTURE_2D, mouseTex);
+       glUniform1i(textShader_uniform_texture, 0);
 
-               glEnableVertexAttribArray(textShader_attribute_tex);
-               glEnableVertexAttribArray(textShader_attribute_coord);
+       glEnableVertexAttribArray(textShader_attribute_tex);
+       glEnableVertexAttribArray(textShader_attribute_coord);
 
-               glDisable(GL_DEPTH_TEST);
+       glDisable(GL_DEPTH_TEST);
 
-               GLfloat mouseCoords[] = {
-                       ui::mouse.x                     ,ui::mouse.y,         1.0, //bottom left
-                       ui::mouse.x+15          ,ui::mouse.y,             1.0, //bottom right
-                       ui::mouse.x+15          ,ui::mouse.y-15,          1.0, //top right
+       GLfloat mouseCoords[] = {
+               ui::mouse.x                     ,ui::mouse.y,         -9.9, //bottom left
+               ui::mouse.x+15          ,ui::mouse.y,             -9.9, //bottom right
+               ui::mouse.x+15          ,ui::mouse.y-15,          -9.9, //top right
 
-                       ui::mouse.x+15          ,ui::mouse.y-15,          1.0, //top right
-                       ui::mouse.x             ,ui::mouse.y-15,          1.0, //top left
-                       ui::mouse.x                     ,ui::mouse.y,             1.0, //bottom left
-               };
+               ui::mouse.x+15          ,ui::mouse.y-15,          -9.9, //top right
+               ui::mouse.x             ,ui::mouse.y-15,          -9.9, //top left
+               ui::mouse.x                     ,ui::mouse.y,             -9.9, //bottom left
+       };
 
-               GLfloat mouseTex[] = {
-                       0.0f, 0.0f, //bottom left
-                       1.0f, 0.0f, //bottom right
-                       1.0f, 1.0f, //top right
+       GLfloat mouseTex[] = {
+               0.0f, 0.0f, //bottom left
+               1.0f, 0.0f, //bottom right
+               1.0f, 1.0f, //top right
 
-                       1.0f, 1.0f, //top right
-                       0.0f, 1.0f, //top left
-                       0.0f, 0.0f, //bottom left
-               };
+               1.0f, 1.0f, //top right
+               0.0f, 1.0f, //top left
+               0.0f, 0.0f, //bottom left
+       };
 
-               glVertexAttribPointer(textShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, 0, mouseCoords);
-               glVertexAttribPointer(textShader_attribute_tex, 2, GL_FLOAT, GL_FALSE, 0, mouseTex);
-               glDrawArrays(GL_TRIANGLES, 0, 6);
+       glVertexAttribPointer(textShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, 0, mouseCoords);
+       glVertexAttribPointer(textShader_attribute_tex, 2, GL_FLOAT, GL_FALSE, 0, mouseTex);
+       glDrawArrays(GL_TRIANGLES, 0, 6);
 
-               glDisableVertexAttribArray(textShader_attribute_coord);
-               glDisableVertexAttribArray(textShader_attribute_tex);
+       glDisableVertexAttribArray(textShader_attribute_coord);
+       glDisableVertexAttribArray(textShader_attribute_tex);
 
-               SDL_GL_SwapWindow(window);
+       SDL_GL_SwapWindow(window);
 }
 
 void logic(){
@@ -562,6 +572,13 @@ void logic(){
        // calculate the world shading value
        worldShade = 50 * sin((game::time::getTickCount() + (DAY_CYCLE / 2)) / (DAY_CYCLE / PI));
 
+       float ws = 75 * sin((game::time::getTickCount() + (DAY_CYCLE / 2)) / (DAY_CYCLE / PI)); 
+       
+       float ambRG = std::clamp(.5f + (-ws / 100.0f), 0.01f, .9f);
+       float ambB =    std::clamp(.5f + (-ws / 80.0f), 0.03f, .9f);
+               
+       ambient = Color(ambRG, ambRG, ambB, 1.0f);
+
        // update fades
        ui::fadeUpdate();
 
index 31777955ee8b96a1ead09712a8991db6a20eae30..bde5fa53176670635ed2da7ebe9fe6807741d654 100644 (file)
@@ -3,7 +3,7 @@ uniform sampler2D normalTex;
 
 varying vec2 texCoord;
 varying vec4 color;
-varying vec3 fragCoord;
+varying vec4 fragCoord;
 
 uniform vec4 ambientLight;
 uniform vec4 light[128];
@@ -11,26 +11,25 @@ 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));
+       vec2 texLoc = vec2(texCoord.x, 1-texCoord.y);
+       vec4 pixTex = texture2D(texture, texLoc);
     if (pixTex.a < 0.1f) 
                discard;
+  
        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]);          
+       if (lightImpact > 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/(light[i].w*light[i].w), 0.0f, 1.0f);
+                       attenuation *= attenuation;
+
+                       shadeColor += (vec4(attenuation, attenuation, attenuation, 0.0f) * vec4(lightColor[i])) * lightImpact;          
+               }
        }
-       shadeColor += ambientLight;     
+       shadeColor += ambientLight;
 
        gl_FragColor = pixTex * color * shadeColor;
 }
index df814e6ce3f0fd4a31c0eb08c3ddd3af4f5f2bbc..0d5e65e1e9cbe991066c20e7c9bd8843f7308ab2 100644 (file)
@@ -7,11 +7,11 @@ uniform mat4 transform;
 
 varying vec2 texCoord;
 varying vec4 color;
-varying vec3 fragCoord;
+varying vec4 fragCoord;
 
 void main(){
        color = tex_color;
     texCoord = tex_coord;
-    gl_Position = ortho * transform * vec4(coord2d.xyz, 1.0);
-       fragCoord = vec3(gl_Position.xyz);
+    fragCoord = vec4(coord2d.xyz, 1.0);
+       gl_Position = ortho * transform * fragCoord;
 }
index e235f51bb48c784e86a438cf5afafbb3ee197766..ede5eeb1e4938c0b6953bf6bb415897645946e3f 100644 (file)
@@ -91,6 +91,11 @@ void items(void)
 
                        ItemMap.push_back(new Food());
 
+               // light
+               } else if (strCaseCmp(name, "light")) {
+                               
+                       ItemMap.push_back(new ItemLight());
+
                // if type was not specified make it a base item
                } else {
 
@@ -98,7 +103,9 @@ void items(void)
                }
 
                // set how much of the item we can stack
-               ItemMap.back()->maxStackSize = exml->UnsignedAttribute("maxStackSize");
+               if(exml->QueryUnsignedAttribute("maxStackSize", &ItemMap.back()->maxStackSize) != XML_NO_ERROR) {
+                       ItemMap.back()->maxStackSize = 1;
+               }
 
                // set all of the texture frames we can use
                ItemMap.back()->tex = new Texturec(1, exml->Attribute("sprite"));
index 6c65b593815ea1597fe856ccd70e6af8c160e49f..eacf5a9ec45c9a74deb6f6d7f5e2b7d90f36b448 100644 (file)
@@ -158,6 +158,11 @@ int Food::useItem()
        return 0;
 }
 
+int ItemLight::useItem()
+{
+       std::cout << "fsdfsdf" << std::endl;
+       return 0;
+}
 
 /**************************************************
 *                       CLONE                     *
@@ -193,6 +198,10 @@ RawFood* RawFood::clone()
        return new RawFood(*this);
 }
 
+ItemLight* ItemLight::clone()
+{
+       return new ItemLight(*this);
+}
 /************************************************************************************
 *                                    ITEM SPECIFIC                                  *
 ************************************************************************************/
index d6df3fd8071b26d40fcaf4c1ecba74eb1fe2646d..a0e70873754204771dbbb9a2612bc271a2217c47 100644 (file)
@@ -143,9 +143,9 @@ void Cat::onHit(unsigned int _health)
 
 bool Cat::bindTex(void)
 {
-    glActiveTexture(GL_TEXTURE0);
+       glActiveTexture(GL_TEXTURE0);
     tex(0);
-    return true;
+       return true;
 }
 
 void Cat::createFromXML(const XMLElement *e)
index 7ae444cb74b3f78c5811881aa783d8be22e87c04..1f6e593d155d2aeb9b6e88ce8ef3b15bb108928d 100644 (file)
@@ -1397,19 +1397,19 @@ EXIT:
                                        heyOhLetsGo = 0;
                                        break;
                                case SDLK_l:
-                                       currentWorld->addLight({player->loc.x + SCREEN_WIDTH/2, player->loc.y},{1.0f,1.0f,1.0f});
-                                       //currentWorld->getLastLight()->follow(player);
+                                       currentWorld->addLight({player->loc.x + SCREEN_WIDTH/2, player->loc.y}, 300.0f, {1.0f,1.0f,1.0f});
+                                       currentWorld->getLastLight()->follow(player);
                                        currentWorld->getLastLight()->makeFlame();
                                        break;
                                case SDLK_f:
-                                       currentWorld->addLight({player->loc.x + SCREEN_WIDTH/2, player->loc.y},{1.0f,1.0f,1.0f});
+                                       currentWorld->addLight({player->loc.x, player->loc.y}, 300.0f, {1.0f,1.0f,1.0f});
                                        break;
                                case SDLK_b:
                                        if (debug)
                                                posFlag ^= true;
                                        else {
                                                currentWorld->addStructure(FIRE_PIT, player->loc.x, player->loc.y, "", "");
-                                               currentWorld->addLight({player->loc.x + SCREEN_WIDTH/2, player->loc.y},{1.0f,1.0f,1.0f});
+                                               currentWorld->addLight({player->loc.x + SCREEN_WIDTH/2, player->loc.y}, 400.0f, {1.0f,1.0f,1.0f});
                                                //currentWorld->getLastLight()->follow(currentWorld->build.back());
                                                currentWorld->getLastLight()->makeFlame();
                                        }
index 2ecccecd12e593e9716967762de74cb7bd290d6e..bb0487ebd51fc73015616cff919610910f5365b1 100644 (file)
@@ -267,7 +267,25 @@ void World::drawBackgrounds(void)
                             0.0f, 0.0f,
                             0.0f, 1.0f,};
 
-    vec2 bg_tex_coord[] = { vec2(0.0f, 0.0f),
+       // TODO scroll backdrop
+       GLfloat bgOff = game::time::getTickCount()/24000.0f;
+       
+       GLfloat topS = .125f + bgOff;
+       GLfloat bottomS = 0.0f + bgOff;
+
+       if (topS < 0.0f) topS += 1.0f;
+       if (bottomS < 0.0f) bottomS += 1.0f;
+       if(bgOff < 0)std::cout << bottomS << "," << topS << std::endl;
+
+       GLfloat scrolling_tex_coord[] = {0.0f,  bottomS,
+                                                                        1.0f,  bottomS,
+                                                                        1.0f,  bottomS,
+                                                                        
+                                                                        1.0f,  bottomS,
+                                                                        0.0f,  bottomS,
+                                                                        0.0f,  bottomS};
+   
+       vec2 bg_tex_coord[] = { vec2(0.0f, 0.0f),
                             vec2(1.0f, 0.0f),
                             vec2(1.0f, 1.0f),
 
@@ -275,13 +293,13 @@ void World::drawBackgrounds(void)
                             vec2(0.0f, 1.0f),
                             vec2(0.0f, 0.0f)};
 
-    GLfloat back_tex_coord[] = {offset.x - backgroundOffset.x - 5, offset.y + backgroundOffset.y, 9.9f,
-                                offset.x + backgroundOffset.x + 5, offset.y + backgroundOffset.y, 9.9f,
+    GLfloat back_tex_coord[] = {offset.x - backgroundOffset.x - 5, offset.y - backgroundOffset.y, 9.9f,
                                 offset.x + backgroundOffset.x + 5, offset.y - backgroundOffset.y, 9.9f,
+                                offset.x + backgroundOffset.x + 5, offset.y + backgroundOffset.y, 9.9f,
 
-                                offset.x + backgroundOffset.x + 5, offset.y - backgroundOffset.y, 9.9f,
-                                offset.x - backgroundOffset.x - 5, offset.y - backgroundOffset.y, 9.9f,
-                                offset.x - backgroundOffset.x - 5, offset.y + backgroundOffset.y, 9.9f};
+                                offset.x + backgroundOffset.x + 5, offset.y + backgroundOffset.y, 9.9f,
+                                offset.x - backgroundOffset.x - 5, offset.y + backgroundOffset.y, 9.9f,
+                                offset.x - backgroundOffset.x - 5, offset.y - backgroundOffset.y, 9.9f};
 
     GLfloat fron_tex_coord[] = {offset.x - backgroundOffset.x - 5, offset.y + backgroundOffset.y, 9.8f,
                                 offset.x + backgroundOffset.x + 5, offset.y + backgroundOffset.y, 9.8f,
@@ -292,25 +310,32 @@ void World::drawBackgrounds(void)
                                 offset.x - backgroundOffset.x - 5, offset.y + backgroundOffset.y, 9.8f};
     
        glUseProgram(worldShader);
+       glUniform1f(worldShader_uniform_light_impact, 0.0f);
+       glUniform4f(worldShader_uniform_ambient, 1.0, 1.0, 1.0, 1.0);
 
     glEnableVertexAttribArray(worldShader_attribute_coord);
     glEnableVertexAttribArray(worldShader_attribute_tex);
 
+       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+
     bgTex(0);
        glUniform4f(worldShader_uniform_color, 1.0, 1.0, 1.0, 1.0);
-    glVertexAttribPointer(worldShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, 0, back_tex_coord);
-    glVertexAttribPointer(worldShader_attribute_tex, 2, GL_FLOAT, GL_FALSE, 0, tex_coord);
+       glVertexAttribPointer(worldShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, 0, back_tex_coord);
+    glVertexAttribPointer(worldShader_attribute_tex, 2, GL_FLOAT, GL_FALSE, 0, scrolling_tex_coord);
     glDrawArrays(GL_TRIANGLES, 0 , 6);
 
        bgTex++;
-       glUniform4f(worldShader_uniform_color, .8, .8, .8, 1.3 - static_cast<float>(alpha)/255.0f);
-    glVertexAttribPointer(worldShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, 0, fron_tex_coord);
+       glUniform4f(worldShader_uniform_color, 1.0, 1.0, 1.0, 1.3 - static_cast<float>(alpha)/255.0f);
+       
+       glVertexAttribPointer(worldShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, 0, fron_tex_coord);
     glVertexAttribPointer(worldShader_attribute_tex, 2, GL_FLOAT, GL_FALSE, 0, tex_coord);
     glDrawArrays(GL_TRIANGLES, 0 , 6);
 
-               
-       static GLuint starTex = Texture::genColor(Color(255, 255, 255));
-       const static float stardim = 2;
+       // TODO make stars dynamic
+       //static GLuint starTex = Texture::genColor(Color(255, 255, 255));
+       static GLuint starTex = Texture::loadTexture("assets/style/classic/bg/star.png");
+       const static float stardim = 24;
        GLfloat star_coord[star.size() * 5 * 6 + 1];
     GLfloat *si = &star_coord[0];              
 
@@ -321,72 +346,77 @@ void World::drawBackgrounds(void)
                for (auto &s : star) {
                        *(si++) = s.x + xcoord;
                        *(si++) = s.y,
-                       *(si++) = 9.8;
+                       *(si++) = 9.7f;
 
                        *(si++) = 0.0;
                        *(si++) = 0.0;
                        
                        *(si++) = s.x + xcoord + stardim;
                        *(si++) = s.y,
-                       *(si++) = 9.8;
+                       *(si++) = 9.7f;
                        
                        *(si++) = 1.0;
                        *(si++) = 0.0;
                        
                        *(si++) = s.x + xcoord + stardim;
                        *(si++) = s.y + stardim,
-                       *(si++) = 9.8;
+                       *(si++) = 9.7f;
                        
                        *(si++) = 1.0;
                        *(si++) = 1.0;
                        
                        *(si++) = s.x + xcoord + stardim;
                        *(si++) = s.y + stardim,
-                       *(si++) = 9.8;
+                       *(si++) = 9.7f;
                        
                        *(si++) = 1.0;
                        *(si++) = 1.0;
                        
                        *(si++) = s.x + xcoord;
                        *(si++) = s.y + stardim,
-                       *(si++) = 9.8;
+                       *(si++) = 9.7f;
                        
                        *(si++) = 0.0;
                        *(si++) = 1.0;
                        
                        *(si++) = s.x + xcoord;
                        *(si++) = s.y,
-                       *(si++) = 9.8;
+                       *(si++) = 9.7f;
                        
                        *(si++) = 0.0;
                        *(si++) = 0.0;
                }
                glBindTexture(GL_TEXTURE_2D, starTex);
-               glUniform4f(worldShader_uniform_color, 1.0, 1.0, 1.0, (255.0f - (randGet() % 200 - 100)) / 255.0f);
-       
+               //glUniform4f(worldShader_uniform_color, 1.0, 1.0, 1.0, (255.0f - (randGet() % 200 - 100)) / 255.0f);
+               glUniform4f(worldShader_uniform_color, 1.0, 1.0, 1.0, 1.3 - static_cast<float>(alpha)/255.0f);
+
                glVertexAttribPointer(worldShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), &star_coord[0]);
                glVertexAttribPointer(worldShader_attribute_tex, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), &star_coord[3]);
                glDrawArrays(GL_TRIANGLES, 0, star.size() * 6);
+               
        }
-    glDisableVertexAttribArray(worldShader_attribute_coord);
+    
+       glDisableVertexAttribArray(worldShader_attribute_coord);
     glDisableVertexAttribArray(worldShader_attribute_tex);
 
        glUniform4f(worldShader_uniform_color, 1.0, 1.0, 1.0, 1.0);
+       glUniform4f(worldShader_uniform_ambient, ambient.red, ambient.green, ambient.blue, 1.0);
     glUseProgram(0);
 
 
     std::vector<vec3> bg_items;
 
        bgTex++;
+       dim2 mountainDim = bgTex.getTextureDim();
     auto xcoord = width / 2 * -1 + offset.x * 0.85f;
-       for (unsigned int i = 0; i <= worldData.size() * HLINE / 1920; i++) {
-        bg_items.push_back(vec3(1920 * i       + xcoord, GROUND_HEIGHT_MINIMUM, 8.0f));
-        bg_items.push_back(vec3(1920 * (i + 1) + xcoord, GROUND_HEIGHT_MINIMUM, 8.0f));
-        bg_items.push_back(vec3(1920 * (i + 1) + xcoord, GROUND_HEIGHT_MINIMUM + 1080, 8.0f));
-
-        bg_items.push_back(vec3(1920 * (i + 1) + xcoord, GROUND_HEIGHT_MINIMUM + 1080, 8.0f));
-        bg_items.push_back(vec3(1920 * i       + xcoord, GROUND_HEIGHT_MINIMUM + 1080, 8.0f));
-        bg_items.push_back(vec3(1920 * i       + xcoord, GROUND_HEIGHT_MINIMUM, 8.0f));
+       for (unsigned int i = 0; i <= worldData.size() * HLINE / mountainDim.x; i++) {
+        bg_items.push_back(vec3(mountainDim.x * i       + xcoord, GROUND_HEIGHT_MINIMUM,                                8.0f));
+        bg_items.push_back(vec3(mountainDim.x * (i + 1) + xcoord, GROUND_HEIGHT_MINIMUM,                                8.0f));
+        bg_items.push_back(vec3(mountainDim.x * (i + 1) + xcoord, GROUND_HEIGHT_MINIMUM + mountainDim.y, 8.0f));
+
+        bg_items.push_back(vec3(mountainDim.x * (i + 1) + xcoord, GROUND_HEIGHT_MINIMUM + mountainDim.y, 8.0f));
+        bg_items.push_back(vec3(mountainDim.x * i       + xcoord, GROUND_HEIGHT_MINIMUM + mountainDim.y, 8.0f));
+        bg_items.push_back(vec3(mountainDim.x * i       + xcoord, GROUND_HEIGHT_MINIMUM,                                8.0f));
        }
 
     std::vector<GLfloat> bg_i;
@@ -406,6 +436,7 @@ void World::drawBackgrounds(void)
     }
 
     glUseProgram(worldShader);
+       glUniform1f(worldShader_uniform_light_impact, 0.01);
 
     glEnableVertexAttribArray(worldShader_attribute_coord);
     glEnableVertexAttribArray(worldShader_attribute_tex);
@@ -423,15 +454,16 @@ void World::drawBackgrounds(void)
        for (unsigned int i = 0; i < 4; i++) {
         std::vector<vec3>c;
                bgTex++;
-        auto xcoord = offset.x * bgDraw[i][2];
-               for (int j = worldStart; j <= -worldStart; j += 600) {
-            c.push_back(vec3(j       + xcoord, GROUND_HEIGHT_MINIMUM, 7-(i*.1)));
-            c.push_back(vec3(j + 600 + xcoord, GROUND_HEIGHT_MINIMUM, 7-(i*.1)));
-            c.push_back(vec3(j + 600 + xcoord, GROUND_HEIGHT_MINIMUM + 400, 7-(i*.1)));
-
-            c.push_back(vec3(j + 600 + xcoord, GROUND_HEIGHT_MINIMUM + 400, 7-(i*.1)));
-            c.push_back(vec3(j       + xcoord, GROUND_HEIGHT_MINIMUM + 400, 7-(i*.1)));
-            c.push_back(vec3(j       + xcoord, GROUND_HEIGHT_MINIMUM, 7-(i*.1)));
+        dim2 dim = bgTex.getTextureDim();
+               auto xcoord = offset.x * bgDraw[i][2];
+               for (int j = worldStart; j <= -worldStart; j += dim.x) {
+            c.push_back(vec3(j         + xcoord, GROUND_HEIGHT_MINIMUM,                7-(i*.1)));
+            c.push_back(vec3(j + dim.x + xcoord, GROUND_HEIGHT_MINIMUM,                7-(i*.1)));
+            c.push_back(vec3(j + dim.x + xcoord, GROUND_HEIGHT_MINIMUM + dim.y, 7-(i*.1)));
+
+            c.push_back(vec3(j + dim.x + xcoord, GROUND_HEIGHT_MINIMUM + dim.y, 7-(i*.1)));
+            c.push_back(vec3(j         + xcoord, GROUND_HEIGHT_MINIMUM + dim.y, 7-(i*.1)));
+            c.push_back(vec3(j         + xcoord, GROUND_HEIGHT_MINIMUM,                7-(i*.1)));
                }
 
         bg_i.clear();
@@ -451,6 +483,7 @@ void World::drawBackgrounds(void)
         }
 
         glUseProgram(worldShader);
+               glUniform1f(worldShader_uniform_light_impact, 0.075f + (0.2f*i));
 
         glEnableVertexAttribArray(worldShader_attribute_coord);
         glEnableVertexAttribArray(worldShader_attribute_tex);
@@ -475,10 +508,18 @@ void World::draw(Player *p)
 
        drawBackgrounds();
 
-
-    for (auto &l : light) {
-        if (l.belongsTo) {
-            l.loc.x = l.following->loc.x + SCREEN_WIDTH / 2;
+       uint ls = light.size();
+       
+       GLfloat *lightCoords = new GLfloat[light.size() * 4];
+       GLfloat *lightColors = new GLfloat[light.size() * 4];
+       
+       uint lpIndex = 0;
+       uint lcIndex = 0;
+               
+       for (uint i = 0; i < ls; i++) {
+               auto &l = light[i];
+               if (l.belongsTo) {
+            l.loc.x = l.following->loc.x;
             l.loc.y = l.following->loc.y;
         }
         if (l.flame) {
@@ -488,7 +529,25 @@ void World::draw(Player *p)
         } else {
             l.fireFlicker = 1;
         }
-    }
+
+               lightCoords[lpIndex++] = l.loc.x;
+               lightCoords[lpIndex++] = l.loc.y;
+               lightCoords[lpIndex++] = 0.0;
+               lightCoords[lpIndex++] = l.radius; 
+    
+               lightColors[lcIndex++] = l.color.red;
+               lightColors[lcIndex++] = l.color.green;
+               lightColors[lcIndex++] = l.color.blue;
+               lightColors[lcIndex++] = 1.0;
+       }
+
+       glUseProgram(worldShader);
+       
+       glUniform4fv(worldShader_uniform_light, ls, lightCoords);
+       glUniform4fv(worldShader_uniform_light_color, ls, lightColors);
+       glUniform1i(worldShader_uniform_light_amt, ls);
+
+       glUseProgram(0);
 
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
@@ -545,6 +604,7 @@ void World::draw(Player *p)
     }
 
     glUseProgram(worldShader);
+       glUniform1f(worldShader_uniform_light_impact, 0.45f);
 
     glEnableVertexAttribArray(worldShader_attribute_coord);
     glEnableVertexAttribArray(worldShader_attribute_tex);
@@ -629,6 +689,7 @@ void World::draw(Player *p)
     }
 
     glUseProgram(worldShader);
+       glUniform1f(worldShader_uniform_light_impact, 1.0f);
 
     glEnableVertexAttribArray(worldShader_attribute_coord);
     glEnableVertexAttribArray(worldShader_attribute_tex);
@@ -1506,10 +1567,10 @@ addParticle(float x, float y, float w, float h, float vx, float vy, Color color,
 }
 
 void World::
-addLight(vec2 loc, Color color)
+addLight(vec2 loc, float radius, Color color)
 {
        if (light.size() < 64)
-        light.emplace_back(loc, color, 1);
+        light.emplace_back(loc, radius, color);
 }
 
 void World::
index 7be0e08d4f8072dd155ee7fcd7b4dd140d391209..2aec9ef34381eaa4d6df8557f220d63912e3736e 100644 (file)
@@ -86,5 +86,6 @@ And it wasn't stormy.
                <give id="Hunters Bow" count="1"/>
                <give id="Crude Arrow" count="110"/>
                <give id="Fried Chicken" count="1"/>
+               <give id="Mossy Torch"  count="1"/>
        </text>
 </Dialog>