]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
Hey, that's pretty good lighting!
authordrumsetmonkey <abelleisle@roadrunner.com>
Thu, 7 Jan 2016 13:25:49 +0000 (08:25 -0500)
committerdrumsetmonkey <abelleisle@roadrunner.com>
Thu, 7 Jan 2016 13:25:49 +0000 (08:25 -0500)
14 files changed:
1  2 
assets/grass.png
assets/house1N.png
assets/names_en-us
assets/pages/gootaGoFast.png
include/common.h
include/entities.h
include/world.h
main.cpp
src/entities.cpp
src/gameplay.cpp
src/inventory.cpp
src/ui.cpp
src/world.cpp
test.frag

index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..e05fb9b15e87e90e7a14af4a4d428cdc44de21ef
new file mode 100644 (file)
Binary files differ
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..02855335246d1dca3a42e10928b064bcf14ceed6
new file mode 100644 (file)
Binary files differ
index a841bb891fd11ae60b8278aa68ead0815bc4c46c,a841bb891fd11ae60b8278aa68ead0815bc4c46c..bc2c212727bde3b99d56b5cb9a26a75ab078d745
@@@ -55,7 -55,7 +55,7 @@@ mPing
  mShrek
  mLogan
  mJohn Cena
--mDex Dogtective
++mDexDogtective
  fShani
  fIsidra
  fAja
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..a113f5d940cb5b89c7b75ef7883564e469681eac
new file mode 100644 (file)
Binary files differ
index 9dcc1104bafbdbf6aed6e0512bc64d273c9531d3,08ec73f625cf758d2a3efa1577d22c08680b881d..207b95f9ef007fc6debb782beb25b79f15de3f73
@@@ -46,6 -45,6 +46,12 @@@ typedef struct 
        float y;
  } vec2;
  
++typedef struct {
++      float x;
++      float y;
++      float z;
++} vec3;
++
  /**
   * This structure contains two sets of coordinates for ray drawing.
   */
@@@ -142,6 -141,6 +148,8 @@@ extern vec2 offset
   */
  extern unsigned int loops;
  
++extern GLuint shaderProgram;
++
  /**
   *    Prints a formatted debug message to the console, along with the callee's file and line
   *    number.
index 7a972008cb91cddb01257b6ba675df1a43dcfd7a,6d192fe2b66a89328db183d55ac2fb10da12794d..a4bc282114b1f4c08ec4721a275a6b9e777114a1
@@@ -124,6 -126,6 +126,7 @@@ public
        GENDER  gender;
        
        Texturec *tex;
++      Texturec *ntex;
  
        unsigned int randDialog;
  
diff --cc include/world.h
index 0a2396562f716d0f24c1ee82c1cef0f3a9ca51b5,4b3a8918c7200fe1f83b8041beb1127d94825bbd..e10d0dc64e55f6fa8eaffd7931d83dac9e23c924
@@@ -26,7 -26,7 +26,7 @@@
   * Defines how many game ticks it takes for a day to elapse.
   */
  
--#define DAY_CYCLE 3000
++#define DAY_CYCLE 12000
  
  /**
   * The background type enum.
@@@ -51,6 -51,6 +51,11 @@@ typedef enum 
        RAIN            /**< Rain (not implemented :) )*/
  } WEATHER;
  
++
++typedef struct{
++      vec2 loc;
++      Color color;
++}Light;
  /**
   * The line structure.
   * This structure is used to store the world's ground, stored in vertical
@@@ -165,14 -165,14 +170,16 @@@ public
        std::vector<Entity              *>      entity;
        std::vector<Object              *>      object;
        std::vector<Particles   *>      particles;
++      std::vector<Light        >  light;
        
-       void addStructure(_TYPE t,BUILD_SUB sub,float x,float y,World *outside,World *inside);
-       void addVillage(int bCount, int npcMin, int npcMax,_TYPE t,float x,float y,World *outside,World *inside);
+       void addStructure(_TYPE t,BUILD_SUB sub,float x,float y,World *inside);
+       void addVillage(int bCount, int npcMin, int npcMax,_TYPE t,float x,float y,World *outside);
        void addMob(int t,float x,float y);
        void addMob(int t,float x,float y,void (*hey)(Mob *));
        void addNPC(float x,float y);
        void addObject(ITEM_ID, bool, const char *, float, float);
        void addParticle(float, float, float, float, float, float, Color color, int);
++      void addLight(vec2, Color);
        
        void update(Player *p,unsigned int delta);
        
diff --cc main.cpp
index 014d9504b0fcb20913c3b7974cea540e5525a320,7eaaa8441fe2cb117e4a55bfcbdf0711a7fbfa98..c174f11d346961dcf559c081b632282b4b1c3df4
+++ b/main.cpp
@@@ -197,10 -198,15 +198,10 @@@ extern int  fadeIntensity
  /*******************************************************************************
   * MAIN ************************************************************************
   *******************************************************************************/
 -
 -#include <X11/Xlib.h>
--
  int main(/*int argc, char *argv[]*/){
        //*argv = (char *)argc;
        gameRunning=false;
 -      
 -      XInitThreads();
 -      
++              
        /*!
         *      (Attempt to) Initialize SDL libraries so that we can use SDL facilities and eventually
         *      make openGL calls. Exit if there was an error.
        if((err=glewInit()) != GLEW_OK){
                std::cout << "GLEW was not able to initialize! Error: " << glewGetErrorString(err) << std::endl;
                return -1;
--      }
++      }       
        
        /*
         *      Initialize the FreeType libraries and select what font to use using functions from the ui
@@@ -598,7 -607,7 +599,10 @@@ void render()
  
        player->near=true;                      // Draw the player's name
  
++      //glUniform2f(glGetUniformLocation(shaderProgram, "lightLocation"), 640,100);
        currentWorld->draw(player);
++      //glUniform3f(glGetUniformLocation(shaderProgram, "lightColor"), 0,1.0f,0);
++
  
        /*
         *      Apply shaders if desired.
                }
                glUseProgramObjectARB(0);
        }
 -      player->inv->draw();
 +
-       glUseProgramObjectARB(shaderProgram);
-       glUniform2f(glGetUniformLocation(shaderProgram, "lightLocation"), 250,250);
-       glUniform3f(glGetUniformLocation(shaderProgram, "lightColor"), 1,0,0);
-       glColor4f(0.0f,0.0f,0.0f,1.0f);
-       glRectf(-SCREEN_WIDTH/2,0,SCREEN_WIDTH/2,SCREEN_HEIGHT);
-       glUseProgramObjectARB(0);
-       player->inv->draw();
        
++      player->inv->draw();
++
        /*
         *      Here we draw a black overlay if it's been requested.
        */
index cd8d29e67e68f4093f14ca0bcec18d2b767cac99,c307a31d9dd00810eca8c9f6767aa8e84b0d1d01..d12a1ca69203d6c2a3cc51e373a7c9f6aee5c248
@@@ -126,6 -128,6 +128,7 @@@ Structures::Structures(){ //sets the st
        near  = false;
        
        tex = new Texturec(3,"assets/house1.png", "assets/house2.png", "assets/fountain1.png");
++      ntex = new Texturec(1, "assets/house1N.png");
        
        inWorld = NULL;
        name = NULL;
@@@ -196,6 -198,6 +199,7 @@@ Object::~Object()
  void Entity::draw(void){              //draws the entities
        glPushMatrix();
        glColor3ub(255,255,255);
++      //glUniform1i(glGetUniformLocation(shaderProgram, "sampler"), 0);
        if(type==NPCT){
                if(NPCp(this)->aiFunc.size()){
                        glColor3ub(255,255,0);
                        //currentWorld->addParticle(loc.x,loc.y-HLINE,HLINE,HLINE,0,0,{0.0f,.17f,0.0f},1000);
                        if(up){
                                if(++texState==2)up=false;
++                              glActiveTexture(GL_TEXTURE0);
                                tex->bindNext();
                        }else{
                                if(!--texState)up=true;
++                              glActiveTexture(GL_TEXTURE0);
                                tex->bindPrev();
                        }
                }
                if(!ground){
++                      glActiveTexture(GL_TEXTURE0 + 0);
                        tex->bind(0);
                }else if(vel.x){
++                      glActiveTexture(GL_TEXTURE0 + 0);
                        tex->bind(texState);
                }else{
++                      glActiveTexture(GL_TEXTURE0 + 0);
                        tex->bind(1);
                }
                break;
        case MOBT:
                switch(subtype){
                        case MS_RABBIT:
++                              glActiveTexture(GL_TEXTURE0 + 0);
                                tex->bind(!ground);
                                break;
                        case MS_TRIGGER:
                        case MS_BIRD:
                        case MS_DOOR:
                        default:
++                              glActiveTexture(GL_TEXTURE0 + 0);
                                tex->bind(0);
                                break;
                }
                for(auto &strt : currentWorld->build){
                        if(this == strt){
                                if(strt->bsubtype == HOUSE){
++                                      glActiveTexture(GL_TEXTURE1);
++                                      ntex->bind(0);
++                                      //When rendering an objectwith this program.
++                                      glActiveTexture(GL_TEXTURE0 + 0);
                                        tex->bind(0);
++                                      //glBindSampler(0, linearFiltering);
++
++
                                }else if(strt->bsubtype == HOUSE2){
++                                      glActiveTexture(GL_TEXTURE0 + 0);
                                        tex->bind(1);
                                }else if(strt->bsubtype == FOUNTAIN){
++                                      glActiveTexture(GL_TEXTURE0 + 0);
                                        tex->bind(2);
                                }
                        }
                } 
                break;
        default:
++              glActiveTexture(GL_TEXTURE0 + 0);
                tex->bind(0);
                break;
        }
        glColor3ub(255,255,255);
++      glUseProgram(shaderProgram);
++      glUniform1i(glGetUniformLocation(shaderProgram, "sampler"), 0);
        glBegin(GL_QUADS);
                glTexCoord2i(0,1);glVertex2i(loc.x, loc.y);
                glTexCoord2i(1,1);glVertex2i(loc.x + width, loc.y);
                glTexCoord2i(1,0);glVertex2i(loc.x + width, loc.y + height);
                glTexCoord2i(0,0);glVertex2i(loc.x, loc.y + height);
        glEnd();
++      glUseProgram(0);
  NOPE:
        glDisable(GL_TEXTURE_2D);
        glMatrixMode(GL_MODELVIEW);
index d43981409d445b5213abd3eca0a493c8b22b666a,ba2c8d9f0e0d7e6d15976b6fb2be030a10cf3e19..1c83bd810712faaea1c5391ec4fc20a7acd76c10
@@@ -118,8 -121,8 +121,8 @@@ void initEverything(void)
        worldSpawnHill3->setBGM("assets/music/ozone.wav");
        worldSpawnHill3->addMob(MS_TRIGGER,-500,0,worldSpawnHill3_itemGet);
        worldSpawnHill3->addMob(MS_TRIGGER,0,0,worldSpawnHill3_itemSee);
--      worldSpawnHill3->addObject(TEST_ITEM,false,"",-200,300);
-       worldSpawnHill3->addMob(MS_TRIGGER,400,0,worldSpawnHill3_leave);
++      worldSpawnHill3->addObject(FLASHLIGHT,false,"",-200,300);
+       worldSpawnHill3->addMob(MS_TRIGGER,650,0,worldSpawnHill3_leave);
        worldSpawnHill3->addHole(800,1000);
        
        worldSpawnHill1->toRight = worldSpawnHill2;
        //playerSpawnHill->addMob(MS_TRIGGER,-1300,0,CUTSCENEEE);*/
  
  
-       currentWorld = worldSpawnHill1;
-       worldSpawnHill2->addStructure(STRUCTURET,HOUSE,(rand()%120*HLINE),100,worldSpawnHill1,worldSpawnHill2);
+       worldSpawnHill2_Building1 = new IndoorWorld();
+       worldSpawnHill2_Building1->generate(300);
+       worldSpawnHill2_Building1->setBackground(BG_WOODHOUSE);
+       worldSpawnHill2_Building1->setBGM("assets/music/theme_jazz.wav");
+       worldSpawnHill2->addStructure(STRUCTURET,HOUSE,(rand()%120*HLINE),100,worldSpawnHill2_Building1);
++      worldSpawnHill2->addLight({300,100},{1.0f,1.0f,1.0f});
        
-       worldSpawnHill2->addStructure(STRUCTURET,HOUSE,(rand()%120*HLINE),100,worldSpawnHill1,worldSpawnHill2);
++      //worldSpawnHill2->addStructure(STRUCTURET,HOUSE,(rand()%120*HLINE),100,worldSpawnHill1,worldSpawnHill2);
        player = new Player();
        player->spawn(200,100);
-       
+       currentWorld = worldSpawnHill1; 
        currentWorld->bgmPlay(NULL);
-       
        atexit(destroyEverything);
  }
  
index c0f416333a2ebc2f54c1fbf264f319837d704e7f,c0f416333a2ebc2f54c1fbf264f319837d704e7f..b6819d12fb1e08e8841c07292b194916ec583e1b
@@@ -291,7 -291,7 +291,8 @@@ void itemDraw(Player *p,ITEM_ID id,ITEM
        default:
                hangle = 0.0f;
        }
--
++      glUseProgram(shaderProgram);
++      glUniform1i(glGetUniformLocation(shaderProgram, "sampler"), 0);
        glTranslatef(itemLoc.x,itemLoc.y,0);
        glRotatef(hangle, 0.0f, 0.0f, 1.0f);
        glTranslatef(-itemLoc.x,-itemLoc.y,0);
        glDisable(GL_TEXTURE_2D);
        glTranslatef(player->loc.x*2,0,0);
        glPopMatrix();
++      glUseProgram(0);
  }
  
  int Inventory::useItem(void){
diff --cc src/ui.cpp
Simple merge
diff --cc src/world.cpp
index 0ecf7ee74f61d0a136b61f73702fd1afe3f495b3,7f9b1c0117855559877105abeda6f2c0b4eeffd5..b539a8759e2417deae6488576da653d0e93fbf33
@@@ -33,6 -33,6 +33,8 @@@ const char *bgPaths[2][7]=
         NULL}
  };
  
++Texturec *grassT;
++
  const float bgDraw[3][3]={
        {100,240,.6 },
        {150,250,.4 },
@@@ -88,6 -88,6 +90,7 @@@ World::World(void)
        
        star = new vec2[100];
        memset(star,0,100 * sizeof(vec2));
++      grassT = new Texturec(1,"assets/grass.png");
  }
  
  void World::deleteEntities(void){
@@@ -383,27 -383,27 +386,24 @@@ LLLOOP
        width = (-x_start) << 1;
        
        glEnable(GL_TEXTURE_2D);
--      
++
        bgTex->bind(0);
        safeSetColorA(255,255,255,255 - worldShade * 4);
--      
        glBegin(GL_QUADS);
                glTexCoord2i(0,0);glVertex2i( cx_start,SCREEN_HEIGHT);
                glTexCoord2i(1,0);glVertex2i(-cx_start,SCREEN_HEIGHT);
                glTexCoord2i(1,1);glVertex2i(-cx_start,0);
                glTexCoord2i(0,1);glVertex2i( cx_start,0);
        glEnd();
--      
++
        bgTex->bindNext();
--      safeSetColorA(255,255,255,worldShade * 4);
--      
++      safeSetColorA(255,255,255,worldShade * 4);      
        glBegin(GL_QUADS);
                glTexCoord2i(0,0);glVertex2i( cx_start,SCREEN_HEIGHT);
                glTexCoord2i(1,0);glVertex2i(-cx_start,SCREEN_HEIGHT);
                glTexCoord2i(1,1);glVertex2i(-cx_start,0);
                glTexCoord2i(0,1);glVertex2i( cx_start,0);
        glEnd();
--
        glDisable(GL_TEXTURE_2D);
  
        /*
                        
                }
        }
++
        
        glEnable(GL_TEXTURE_2D);
  
        /*
         *      Draw the mountains.
        */
--
        bgTex->bindNext();
        safeSetColorA(150-bgshade,150-bgshade,150-bgshade,220);
        
@@@ -551,79 -551,79 +551,108 @@@ LOOP2
  
        bool hey=false;
        glEnable(GL_TEXTURE_2D);
++      glActiveTexture(GL_TEXTURE0);
        bgTex->bindNext();
++
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); //for the s direction
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); //for the t direction
++      glUseProgram(shaderProgram);
++      glUniform1i(glGetUniformLocation(shaderProgram, "sampler"), 0);
++      glUniform1f(glGetUniformLocation(shaderProgram, "amb"), float(shade+50.0f)/100.0f);
++      if(light.size() == 0){
++              glUniform2f(glGetUniformLocation(shaderProgram, "lightLocation"), 0,-1000);
++              glUniform3f(glGetUniformLocation(shaderProgram, "lightColor"), 0.0f,0.0f,0.0f);
++      }else{
++              for(auto &l : light){
++                      glUniform2f(glGetUniformLocation(shaderProgram, "lightLocation"), l.loc.x-offset.x,l.loc.y);
++                      glUniform3f(glGetUniformLocation(shaderProgram, "lightColor"), l.color.red,l.color.green,l.color.blue);
++              }
++      }
++
        glBegin(GL_QUADS);
--              for(i=is;i<(unsigned)ie-GEN_INC;i++){
--                      cline[i].y+=(yoff-DRAW_Y_OFFSET);                                                                                                                       // Add the y offset
--                      if(!cline[i].y){
--                              cline[i].y=base;
--                              hey=true;
--                              glColor4ub(0,0,0,255);
--                      }else
--                              safeSetColorA(150+shade*2,150+shade*2,150+shade*2,255);
--                      glTexCoord2i(0,0);glVertex2i(cx_start+i*HLINE      ,cline[i].y-GRASS_HEIGHT);
--                      glTexCoord2i(1,0);glVertex2i(cx_start+i*HLINE+HLINE,cline[i].y-GRASS_HEIGHT);
--                      glTexCoord2i(1,(int)(cline[i].y/64)+cline[i].color);glVertex2i(cx_start+i*HLINE+HLINE,0);
--                      glTexCoord2i(0,(int)(cline[i].y/64)+cline[i].color);glVertex2i(cx_start+i*HLINE    ,0);
--                      cline[i].y-=(yoff-DRAW_Y_OFFSET);                                                                                                                       // Restore the line's y value
--                      if(hey){
--                              hey=false;
--                              cline[i].y=0;
--                      }
++      for(i=is;i<(unsigned)ie-GEN_INC;i++){
++              cline[i].y+=(yoff-DRAW_Y_OFFSET);                                                                                                                       // Add the y offset
++              if(!cline[i].y){
++                      cline[i].y=base;
++                      hey=true;
++                      glColor4ub(0,0,0,255);
++              }else safeSetColorA(150+shade*2,150+shade*2,150+shade*2,255);
++              glTexCoord2i(0,0);glVertex2i(cx_start+i*HLINE      ,cline[i].y-GRASS_HEIGHT);
++              glTexCoord2i(1,0);glVertex2i(cx_start+i*HLINE+HLINE,cline[i].y-GRASS_HEIGHT);
++              glTexCoord2i(1,(int)(cline[i].y/64)+cline[i].color);glVertex2i(cx_start+i*HLINE+HLINE,0);
++              glTexCoord2i(0,(int)(cline[i].y/64)+cline[i].color);glVertex2i(cx_start+i*HLINE    ,0);
++              cline[i].y-=(yoff-DRAW_Y_OFFSET);                                                                                                                       // Restore the line's y value
++              if(hey){
++                      hey=false;
++                      cline[i].y=0;
                }
++      }
        glEnd();
++      glUseProgram(0);
        glDisable(GL_TEXTURE_2D);
--      
        /*
         *      Draw grass on every line.
        */
        
        float cgh[2];
--      glBegin(GL_QUADS);
--              for(i=is;i<(unsigned)ie-GEN_INC;i++){
--                      
--                      /*
--                       *      Load the current line's grass values
--                      */
--                      
--                      if(cline[i].y)memcpy(cgh,cline[i].gh,2*sizeof(float));
--                      else              memset(cgh,0                  ,2*sizeof(float));
--                      
--                      
--                      
--                      /*
--                       *      Flatten the grass if the player is standing on it.
--                      */
--                      
--                      if(!cline[i].gs){
--                              cgh[0]/=4;
--                              cgh[1]/=4;
--                      }
--                      
--                      /*
--                       *      Actually draw the grass.
--                      */
--                      
--                      cline[i].y+=(yoff-DRAW_Y_OFFSET);
--                      
--                      safeSetColor(shade,100+shade*1.5,shade);
--                      
--                      glVertex2i(cx_start+i*HLINE        ,cline[i].y+cgh[0]);
--                      glVertex2i(cx_start+i*HLINE+HLINE/2,cline[i].y+cgh[0]);
--                      glVertex2i(cx_start+i*HLINE+HLINE/2,cline[i].y-GRASS_HEIGHT);
--                      glVertex2i(cx_start+i*HLINE                ,cline[i].y-GRASS_HEIGHT);
--                      
--                      glVertex2i(cx_start+i*HLINE+HLINE/2,cline[i].y+cgh[1]);
--                      glVertex2i(cx_start+i*HLINE+HLINE  ,cline[i].y+cgh[1]);
--                      glVertex2i(cx_start+i*HLINE+HLINE  ,cline[i].y-GRASS_HEIGHT);
--                      glVertex2i(cx_start+i*HLINE+HLINE/2,cline[i].y-GRASS_HEIGHT);
--                      
--                      cline[i].y-=(yoff-DRAW_Y_OFFSET);
++
++      glEnable(GL_TEXTURE_2D);
++      glActiveTexture(GL_TEXTURE0);
++      grassT->bind(0);
++      glUseProgram(shaderProgram);
++      glUniform1i(glGetUniformLocation(shaderProgram, "sampler"), 0);         
++      //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); //for the s direction
++      //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); //for the t direction
++      //glBegin(GL_QUADS);
++
++      for(i=is;i<(unsigned)ie-GEN_INC;i++){
++              
++              /*
++               *      Load the current line's grass values
++              */
++              
++              if(cline[i].y)memcpy(cgh,cline[i].gh,2*sizeof(float));
++              else              memset(cgh,0                  ,2*sizeof(float));
++              
++              
++              
++              /*
++               *      Flatten the grass if the player is standing on it.
++              */
++              
++              if(!cline[i].gs){
++                      cgh[0]/=4;
++                      cgh[1]/=4;
                }
--      glEnd();
--      
++              
++              /*
++               *      Actually draw the grass.
++              */
++              
++              cline[i].y+=(yoff-DRAW_Y_OFFSET);
++              safeSetColorA(255,255,255,255);
++              glBegin(GL_QUADS);
++              glTexCoord2i(0,0);glVertex2i(cx_start+i*HLINE        ,cline[i].y+cgh[0]);
++              glTexCoord2i(1,0);glVertex2i(cx_start+i*HLINE+HLINE/2,cline[i].y+cgh[0]);
++              glTexCoord2i(1,1);glVertex2i(cx_start+i*HLINE+HLINE/2,cline[i].y-GRASS_HEIGHT);
++              glTexCoord2i(0,1);glVertex2i(cx_start+i*HLINE            ,cline[i].y-GRASS_HEIGHT);
++              glEnd();
++
++              glBegin(GL_QUADS);
++              glTexCoord2i(0,0);glVertex2i(cx_start+i*HLINE+HLINE/2,cline[i].y+cgh[1]);
++              glTexCoord2i(1,0);glVertex2i(cx_start+i*HLINE+HLINE  ,cline[i].y+cgh[1]);
++              glTexCoord2i(1,1);glVertex2i(cx_start+i*HLINE+HLINE  ,cline[i].y-GRASS_HEIGHT);
++              glTexCoord2i(0,1);glVertex2i(cx_start+i*HLINE+HLINE/2,cline[i].y-GRASS_HEIGHT);
++              glEnd();
++
++              cline[i].y-=(yoff-DRAW_Y_OFFSET);
++      }
++      //glEnd();
++      //glUseProgram(0);
++      glDisable(GL_TEXTURE_2D);
++
++      //glUseProgram(0);
++
        /*
         *      Draw non-structure entities.
        */
@@@ -958,6 -959,6 +988,12 @@@ void World::addParticle(float x, float 
        particles.back()->canMove = true;
  }
  
++void World::addLight(vec2 loc, Color color){
++      light.push_back(Light());
++      light.back().loc = loc;
++      light.back().color = color;
++}
++
  /*void World::removeObject(Object i){
        object.delete[](i);
  }*/
@@@ -1101,19 -1103,21 +1138,34 @@@ void IndoorWorld::draw(Player *p)
        */
        
        glEnable(GL_TEXTURE_2D);
++      glUseProgram(shaderProgram);
++      glUniform1i(glGetUniformLocation(shaderProgram, "sampler"), 0);
++      glUniform1f(glGetUniformLocation(shaderProgram, "amb"), 0.0f);
++      if(light.size() == 0){
++              glUniform2f(glGetUniformLocation(shaderProgram, "lightLocation"), 0,-1000);
++              glUniform3f(glGetUniformLocation(shaderProgram, "lightColor"), 0.0f,0.0f,0.0f);
++      }else{
++              for(auto &l : light){
++                      glUniform2f(glGetUniformLocation(shaderProgram, "lightLocation"), l.loc.x-offset.x,l.loc.y);
++                      glUniform3f(glGetUniformLocation(shaderProgram, "lightColor"), l.color.red,l.color.green,l.color.blue);
++              }
++      }
        
        bgTex->bind(0);
+       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); //for the s direction
+       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); //for the t direction
        glColor4ub(255,255,255,255);
        
        glBegin(GL_QUADS);      
-               for(j = x_start - SCREEN_WIDTH / 2;j < -x_start + SCREEN_WIDTH / 2; j += 512){
-                       glTexCoord2i(1,1);glVertex2i(j    ,0);
-                       glTexCoord2i(0,1);glVertex2i(j+512,0);
-                       glTexCoord2i(0,0);glVertex2i(j+512,512);
-                       glTexCoord2i(1,0);glVertex2i(j    ,512);
-               }
+               //for(j = x_start - SCREEN_WIDTH / 2;j < -x_start + SCREEN_WIDTH / 2; j += 512){
+                       glTexCoord2i(0,1);                                                        glVertex2i( x_start - SCREEN_WIDTH / 2,0);
+                       glTexCoord2i((-x_start*2+SCREEN_WIDTH)/512,1);glVertex2i(-x_start + SCREEN_WIDTH / 2,0);
+                       glTexCoord2i((-x_start*2+SCREEN_WIDTH)/512,0);glVertex2i(-x_start + SCREEN_WIDTH / 2,SCREEN_HEIGHT);
+                       glTexCoord2i(0,0);                                                        glVertex2i( x_start - SCREEN_WIDTH / 2,SCREEN_HEIGHT);
+               //}
        glEnd();
        
++      glUseProgram(0);
        glDisable(GL_TEXTURE_2D);
        
        /*
        /*
         *      Draw the ground.
        */
--      
++      glUseProgram(shaderProgram);
++      glUniform1i(glGetUniformLocation(shaderProgram, "sampler"), 0);
        glBegin(GL_QUADS);
                for(;i < ie - GEN_INC;i++){
                        safeSetColor(150,100,50);
                        glVertex2i(x            ,line[i].y - 50);
                }
        glEnd();
++      glUseProgram(0);
        
        /*
         *      Draw all entities.
diff --cc test.frag
index 18b03df044732e496bbc5c324524aab3d621f3fd,c30ef4d78504e6b986071f0ca6ea4726b0902840..b16ae1a0f967e8956457aaa81532e312d9e56d64
+++ b/test.frag
@@@ -1,17 -1,4 +1,23 @@@
 -#version 120\r
 -void main(){\r
 -      gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);\r
 -}\r
++uniform sampler2D sampler;\r
++\r
 +uniform vec2 lightLocation;\r
 +uniform vec3 lightColor;\r
- uniform float screenHeight;\r
++uniform float amb;\r
++// uniform float lightStrength;\r
++//uniform float screenHeight;\r
++void main() {\r
++      float lightAdd = 1.0f;\r
 +\r
- float radius = 4.9;\r
- float minLight = .01;\r
- float a = .01;\r
- float b = 1.0 / (radius*radius * minLight);\r
++      float dist = length(lightLocation - gl_FragCoord.xy);\r
++      float attenuation=1.0/(1.0+0.01*dist+0.00000000001*dist*dist);\r
 +\r
- void main() {\r
-       float distance = length(lightLocation - gl_FragCoord.xy);\r
-       //float attenuation = 1.0 / (1.0 + a*distance + b*distance*distance);\r
-       float attenuation = clamp(1.0 - distance*distance/(radius*radius), 0.0, 1.0); attenuation *= attenuation;\r
-       vec4 color = vec4(attenuation, attenuation, attenuation, attenuation) * vec4(lightColor, 1);\r
++      //vec4 color = vec4(1.0f,1.0f,1.0f,1.0f);\r
++      vec4 color = vec4(attenuation, attenuation, attenuation, 1.0f) * vec4(lightColor, 1.0f);\r
++      //color = color + vec4((vec3(lightColor.r + amb, lightColor.g + amb, lightColor.b + amb)*0.25f),1.0f);\r
++\r
++      vec2 coords = gl_TexCoord[0].st;\r
++      vec4 tex = texture2D(sampler, coords);\r
 +\r
-       gl_FragColor = color;\r
++      color += vec4(amb,amb,amb,1.0f+amb);\r
++      gl_FragColor = tex * vec4(color)*tex.a;\r
 +}