aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClyne Sullivan <tullivan99@gmail.com>2016-01-07 08:37:49 -0500
committerClyne Sullivan <tullivan99@gmail.com>2016-01-07 08:37:49 -0500
commit81cf23371b94baf608c98d0dd248acfbbd5d2c70 (patch)
tree42282b56ce04e17fcc3f61d6b356b6ac72250915
parentcdd792bc8ba7337e7bd3a9d0b4141c63f17fb9a8 (diff)
parente043a2432c4dacce56a308948188482fb230ff33 (diff)
merge
-rw-r--r--assets/door.pngbin280 -> 252 bytes
-rw-r--r--assets/grass.pngbin0 -> 128 bytes
-rw-r--r--assets/house1N.pngbin0 -> 1464 bytes
-rw-r--r--assets/names_en-us2
-rw-r--r--assets/pages/gootaGoFast.pngbin0 -> 20663 bytes
-rw-r--r--include/common.h11
-rw-r--r--include/entities.h3
-rw-r--r--include/world.h9
-rw-r--r--main.cpp33
-rw-r--r--src/entities.cpp28
-rw-r--r--src/gameplay.cpp2
-rw-r--r--src/inventory.cpp4
-rw-r--r--src/ui.cpp5
-rw-r--r--src/world.cpp186
-rw-r--r--test.frag27
-rw-r--r--xcf/door.xcfbin1628 -> 0 bytes
16 files changed, 209 insertions, 101 deletions
diff --git a/assets/door.png b/assets/door.png
index 582a52d..7db551d 100644
--- a/assets/door.png
+++ b/assets/door.png
Binary files differ
diff --git a/assets/grass.png b/assets/grass.png
new file mode 100644
index 0000000..e05fb9b
--- /dev/null
+++ b/assets/grass.png
Binary files differ
diff --git a/assets/house1N.png b/assets/house1N.png
new file mode 100644
index 0000000..0285533
--- /dev/null
+++ b/assets/house1N.png
Binary files differ
diff --git a/assets/names_en-us b/assets/names_en-us
index a841bb8..bc2c212 100644
--- a/assets/names_en-us
+++ b/assets/names_en-us
@@ -55,7 +55,7 @@ mPingu
mShrek
mLogan
mJohn Cena
-mDex Dogtective
+mDexDogtective
fShani
fIsidra
fAja
diff --git a/assets/pages/gootaGoFast.png b/assets/pages/gootaGoFast.png
new file mode 100644
index 0000000..a113f5d
--- /dev/null
+++ b/assets/pages/gootaGoFast.png
Binary files differ
diff --git a/include/common.h b/include/common.h
index 038bf42..0a868df 100644
--- a/include/common.h
+++ b/include/common.h
@@ -14,6 +14,7 @@
#include <math.h>
#include <string>
#include <fstream>
+#include <thread>
#define GLEW_STATIC
#include <GL/glew.h>
@@ -34,7 +35,7 @@ typedef unsigned int uint;
* This flag lets the compiler know that we want to use shaders.
*/
-#define SHADERSs
+#define SHADERS
/**
* This structure contains a set of coordinates for ease of coding.
@@ -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.
*/
@@ -141,6 +148,8 @@ extern vec2 offset;
*/
extern unsigned int loops;
+extern GLuint shaderProgram;
+
/**
* This class contains a string for identification and a value. It can be used to
* save certain events for and decisions so that they can be recalled later.
diff --git a/include/entities.h b/include/entities.h
index 0f7ac9b..0fcc662 100644
--- a/include/entities.h
+++ b/include/entities.h
@@ -152,6 +152,7 @@ public:
GENDER gender;
Texturec *tex;
+ Texturec *ntex;
unsigned int randDialog;
@@ -169,7 +170,7 @@ public:
void baseLoad(char *);
};
-class Player : public Entity {
+class Player : public Entity{
public:
QuestHandler qh;
bool light = false;
diff --git a/include/world.h b/include/world.h
index cdcea3c..5021fbb 100644
--- a/include/world.h
+++ b/include/world.h
@@ -29,7 +29,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.
@@ -54,6 +54,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
@@ -169,6 +174,7 @@ 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 *inside);
void addVillage(int bCount, int npcMin, int npcMax,_TYPE t,World *inside);
@@ -177,6 +183,7 @@ public:
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);
NPC *getAvailableNPC(void);
diff --git a/main.cpp b/main.cpp
index 2c088cb..1725ccf 100644
--- a/main.cpp
+++ b/main.cpp
@@ -199,11 +199,10 @@ extern int fadeIntensity;
/*******************************************************************************
* MAIN ************************************************************************
*******************************************************************************/
-
int main(/*int argc, char *argv[]*/){
//*argv = (char *)argc;
gameRunning=false;
-
+
/*!
* (Attempt to) Initialize SDL libraries so that we can use SDL facilities and eventually
* make openGL calls. Exit if there was an error.
@@ -301,7 +300,7 @@ int main(/*int argc, char *argv[]*/){
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
@@ -347,7 +346,7 @@ int main(/*int argc, char *argv[]*/){
fragShader = glCreateShader(GL_FRAGMENT_SHADER);
- std::string shaderFileContents = readFile("shader.frag");
+ std::string shaderFileContents = readFile("test.frag");
const GLchar *shaderSource = shaderFileContents.c_str();
GLint bufferln = GL_FALSE;
@@ -579,10 +578,7 @@ void render(){
glOrtho((offset.x-SCREEN_WIDTH/2),(offset.x+SCREEN_WIDTH/2),offset.y-SCREEN_HEIGHT/2,offset.y+SCREEN_HEIGHT/2,-1,1);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
- glLoadIdentity();
- glEnable(GL_STENCIL_TEST);
- glPushMatrix();
-
+ glLoadIdentity();
/*
* glPushAttrib This passes attributes to the renderer so it knows what it can
* render. In our case, GL_DEPTH_BUFFER_BIT allows the renderer to
@@ -608,23 +604,15 @@ 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.
*/
- #ifdef SHADERS
- glUseProgramObjectARB(shaderProgram);
- glUniform2f(glGetUniformLocation(shaderProgram, "lightLocation"), 640,100);
- glUniform3f(glGetUniformLocation(shaderProgram, "lightColor"), 1,1,1);
- glUniform1f(glGetUniformLocation(shaderProgram, "lightStrength"), 100 + (1000-(shade*10)));
- //std::cout << 100 + (1000-(shade*10)) << std::endl;
- glColor4ub(0,0,0,200);
- glRectf(offset.x-SCREEN_WIDTH/2,0,offset.x+SCREEN_WIDTH/2,SCREEN_HEIGHT);
- glUseProgramObjectARB(0);
- #endif //SHADERS
-
handAngle = atan((ui::mouse.y - (player->loc.y + player->height/2)) / (ui::mouse.x - player->loc.x + player->width/2))*180/PI;
if(ui::mouse.x < player->loc.x){
if(handAngle <= 0)
@@ -696,11 +684,15 @@ void render(){
}
glUseProgramObjectARB(0);
}
- player->inv->draw();
+
+ player->inv->draw();
+
/*
* Here we draw a black overlay if it's been requested.
*/
+ //glUseProgramObjectARB(0);
+
if(fadeIntensity){
if(fadeWhite)
@@ -790,6 +782,7 @@ void render(){
static volatile bool objectInteracting = false;
void logic(){
+
/*
* NPCSelected is used to insure that only one NPC is made interactable with the mouse
* if, for example, multiple entities are occupying one space.
diff --git a/src/entities.cpp b/src/entities.cpp
index eb653a9..57a20ef 100644
--- a/src/entities.cpp
+++ b/src/entities.cpp
@@ -77,8 +77,8 @@ Player::Player(){ //sets all of the player specific traits on object creation
subtype = 0;
health = maxHealth = 100;
speed = 1;
- //tex = new Texturec(3, "assets/player1.png", "assets/player.png", "assets/player2.png");
- tex = new Texturec(3, "assets/maybeplayer.png", "assets/maybeplayer.png", "assets/maybeplayer.png");
+ tex = new Texturec(3, "assets/player1.png", "assets/player.png", "assets/player2.png");
+ //tex = new Texturec(3, "assets/maybeplayer.png", "assets/maybeplayer.png", "assets/maybeplayer.png");
inv = new Inventory(PLAYER_INV_SIZE);
}
Player::~Player(){
@@ -120,6 +120,7 @@ Structures::Structures(){ //sets the structure type
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;
@@ -155,7 +156,7 @@ Mob::Mob(int sub){
break;
case MS_DOOR:
width = HLINE * 12;
- height = HLINE * 19;
+ height = HLINE * 20;
tex = new Texturec(1,"assets/door.png");
break;
case MS_PAGE:
@@ -222,6 +223,7 @@ void Object::reloadTexture(void){
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);
@@ -248,23 +250,29 @@ void Entity::draw(void){ //draws the entities
//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:
@@ -274,6 +282,7 @@ void Entity::draw(void){ //draws the entities
case MS_DOOR:
case MS_PAGE:
default:
+ glActiveTexture(GL_TEXTURE0 + 0);
tex->bind(0);
break;
}
@@ -282,26 +291,39 @@ void Entity::draw(void){ //draws the entities
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);
diff --git a/src/gameplay.cpp b/src/gameplay.cpp
index 5b9f509..e8436e7 100644
--- a/src/gameplay.cpp
+++ b/src/gameplay.cpp
@@ -178,10 +178,12 @@ void initEverything(void){
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->getAvailableNPC()->addAIFunc(worldSpawnHill2_Quest1,false);
worldFirstVillage->addVillage(5,0,0,STRUCTURET,worldSpawnHill2_Building1);
+ //worldSpawnHill2->addStructure(STRUCTURET,HOUSE,(rand()%120*HLINE),100,worldSpawnHill1,worldSpawnHill2);
player = new Player();
player->spawn(200,100);
diff --git a/src/inventory.cpp b/src/inventory.cpp
index c0f4163..b6819d1 100644
--- a/src/inventory.cpp
+++ b/src/inventory.cpp
@@ -291,7 +291,8 @@ void itemDraw(Player *p,ITEM_ID id,ITEM_TYPE type){
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);
@@ -307,6 +308,7 @@ void itemDraw(Player *p,ITEM_ID id,ITEM_TYPE type){
glDisable(GL_TEXTURE_2D);
glTranslatef(player->loc.x*2,0,0);
glPopMatrix();
+ glUseProgram(0);
}
int Inventory::useItem(void){
diff --git a/src/ui.cpp b/src/ui.cpp
index b827b43..7979138 100644
--- a/src/ui.cpp
+++ b/src/ui.cpp
@@ -568,7 +568,7 @@ namespace ui {
hub.y-=fontSize*1.15;
glRectf(hub.x,
hub.y,
- hub.x+(player->health/player->maxHealth)*130,
+ hub.x+(player->health/player->maxHealth?player->maxHealth:1)*130,
hub.y+12);
}
@@ -814,6 +814,9 @@ DONE:
case SDLK_RIGHT:
player->inv->sel++;
break;
+ case SDLK_f:
+
+ break;
default:
break;
}
diff --git a/src/world.cpp b/src/world.cpp
index 8b09398..93341f2 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -33,6 +33,8 @@ const char *bgPaths[2][7]={
NULL}
};
+Texturec *grassT;
+
const float bgDraw[3][3]={
{100,240,.6 },
{150,250,.4 },
@@ -203,6 +205,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){
@@ -498,27 +501,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);
/*
@@ -541,13 +541,13 @@ LLLOOP:
}
}
+
glEnable(GL_TEXTURE_2D);
/*
* Draw the mountains.
*/
-
bgTex->bindNext();
safeSetColorA(150-bgshade,150-bgshade,150-bgshade,220);
@@ -666,79 +666,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.
*/
@@ -1078,6 +1107,12 @@ void World::addParticle(float x, float y, float w, float h, float vx, float vy,
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);
}*/
@@ -1230,6 +1265,18 @@ 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
@@ -1245,6 +1292,7 @@ void IndoorWorld::draw(Player *p){
//}
glEnd();
+ glUseProgram(0);
glDisable(GL_TEXTURE_2D);
/*
@@ -1265,7 +1313,8 @@ void IndoorWorld::draw(Player *p){
/*
* Draw the ground.
*/
-
+ glUseProgram(shaderProgram);
+ glUniform1i(glGetUniformLocation(shaderProgram, "sampler"), 0);
glBegin(GL_QUADS);
for(;i < ie - GEN_INC;i++){
safeSetColor(150,100,50);
@@ -1277,6 +1326,7 @@ void IndoorWorld::draw(Player *p){
glVertex2i(x ,line[i].y - 50);
}
glEnd();
+ glUseProgram(0);
/*
* Draw all entities.
diff --git a/test.frag b/test.frag
index c30ef4d..b16ae1a 100644
--- a/test.frag
+++ b/test.frag
@@ -1,4 +1,23 @@
-#version 120
-void main(){
- gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
-}
+uniform sampler2D sampler;
+
+uniform vec2 lightLocation;
+uniform vec3 lightColor;
+uniform float amb;
+// uniform float lightStrength;
+//uniform float screenHeight;
+void main() {
+ float lightAdd = 1.0f;
+
+ float dist = length(lightLocation - gl_FragCoord.xy);
+ float attenuation=1.0/(1.0+0.01*dist+0.00000000001*dist*dist);
+
+ //vec4 color = vec4(1.0f,1.0f,1.0f,1.0f);
+ vec4 color = vec4(attenuation, attenuation, attenuation, 1.0f) * vec4(lightColor, 1.0f);
+ //color = color + vec4((vec3(lightColor.r + amb, lightColor.g + amb, lightColor.b + amb)*0.25f),1.0f);
+
+ vec2 coords = gl_TexCoord[0].st;
+ vec4 tex = texture2D(sampler, coords);
+
+ color += vec4(amb,amb,amb,1.0f+amb);
+ gl_FragColor = tex * vec4(color)*tex.a;
+} \ No newline at end of file
diff --git a/xcf/door.xcf b/xcf/door.xcf
deleted file mode 100644
index ab8e078..0000000
--- a/xcf/door.xcf
+++ /dev/null
Binary files differ