From 3ca4cca09ed9a2b1028928dea98f19bd26ab3b2c Mon Sep 17 00:00:00 2001 From: drumsetmonkey Date: Wed, 6 Apr 2016 07:38:59 -0400 Subject: First world and style --- assets/style/farming/bg/bagels.jpg | Bin 0 -> 259847 bytes assets/style/farming/bg/bagels.png | Bin 0 -> 1252347 bytes assets/style/farming/bg/bg.png | Bin 0 -> 1072758 bytes assets/style/farming/bg/bgFarMountain.png | Bin 0 -> 20172 bytes assets/style/farming/bg/bgWoodTile.png | Bin 0 -> 205428 bytes assets/style/farming/bg/bgb.png | Bin 0 -> 2899454 bytes assets/style/farming/bg/bgfarMountains.png | Bin 0 -> 30875 bytes assets/style/farming/bg/bgn.png | Bin 0 -> 1438185 bytes assets/style/farming/bg/dirt.png | Bin 0 -> 228 bytes assets/style/farming/bg/forestTileBack.png | Bin 0 -> 9657 bytes assets/style/farming/bg/forestTileFar.png | Bin 0 -> 14112 bytes assets/style/farming/bg/forestTileFront.png | Bin 0 -> 26722 bytes assets/style/farming/bg/forestTileMid.png | Bin 0 -> 45450 bytes assets/style/farming/bg/grass.png | Bin 0 -> 128 bytes assets/style/farming/bg/moon.png | Bin 0 -> 2868 bytes assets/style/farming/farmHouse.png | Bin 0 -> 2194 bytes frig.frag | 2 +- include/entities.hpp | 10 ++---- main.cpp | 5 +++ src/world.cpp | 50 +++++++++++++++++++++------- storyXML/0000_SpawnHill.xml | 6 ++-- storyXML/0000_SpawnHill.xml.dat | 2 ++ xml/playerSpawnHill1_Building1.xml | 1 + 23 files changed, 54 insertions(+), 22 deletions(-) create mode 100644 assets/style/farming/bg/bagels.jpg create mode 100644 assets/style/farming/bg/bagels.png create mode 100644 assets/style/farming/bg/bg.png create mode 100644 assets/style/farming/bg/bgFarMountain.png create mode 100644 assets/style/farming/bg/bgWoodTile.png create mode 100644 assets/style/farming/bg/bgb.png create mode 100644 assets/style/farming/bg/bgfarMountains.png create mode 100644 assets/style/farming/bg/bgn.png create mode 100644 assets/style/farming/bg/dirt.png create mode 100644 assets/style/farming/bg/forestTileBack.png create mode 100644 assets/style/farming/bg/forestTileFar.png create mode 100644 assets/style/farming/bg/forestTileFront.png create mode 100644 assets/style/farming/bg/forestTileMid.png create mode 100644 assets/style/farming/bg/grass.png create mode 100644 assets/style/farming/bg/moon.png create mode 100644 assets/style/farming/farmHouse.png diff --git a/assets/style/farming/bg/bagels.jpg b/assets/style/farming/bg/bagels.jpg new file mode 100644 index 0000000..fb68d2e Binary files /dev/null and b/assets/style/farming/bg/bagels.jpg differ diff --git a/assets/style/farming/bg/bagels.png b/assets/style/farming/bg/bagels.png new file mode 100644 index 0000000..2ee843b Binary files /dev/null and b/assets/style/farming/bg/bagels.png differ diff --git a/assets/style/farming/bg/bg.png b/assets/style/farming/bg/bg.png new file mode 100644 index 0000000..2dbc3f9 Binary files /dev/null and b/assets/style/farming/bg/bg.png differ diff --git a/assets/style/farming/bg/bgFarMountain.png b/assets/style/farming/bg/bgFarMountain.png new file mode 100644 index 0000000..eb703bb Binary files /dev/null and b/assets/style/farming/bg/bgFarMountain.png differ diff --git a/assets/style/farming/bg/bgWoodTile.png b/assets/style/farming/bg/bgWoodTile.png new file mode 100644 index 0000000..95b0667 Binary files /dev/null and b/assets/style/farming/bg/bgWoodTile.png differ diff --git a/assets/style/farming/bg/bgb.png b/assets/style/farming/bg/bgb.png new file mode 100644 index 0000000..278e9b0 Binary files /dev/null and b/assets/style/farming/bg/bgb.png differ diff --git a/assets/style/farming/bg/bgfarMountains.png b/assets/style/farming/bg/bgfarMountains.png new file mode 100644 index 0000000..fa6b349 Binary files /dev/null and b/assets/style/farming/bg/bgfarMountains.png differ diff --git a/assets/style/farming/bg/bgn.png b/assets/style/farming/bg/bgn.png new file mode 100644 index 0000000..2aa3995 Binary files /dev/null and b/assets/style/farming/bg/bgn.png differ diff --git a/assets/style/farming/bg/dirt.png b/assets/style/farming/bg/dirt.png new file mode 100644 index 0000000..11252ac Binary files /dev/null and b/assets/style/farming/bg/dirt.png differ diff --git a/assets/style/farming/bg/forestTileBack.png b/assets/style/farming/bg/forestTileBack.png new file mode 100644 index 0000000..0ea6022 Binary files /dev/null and b/assets/style/farming/bg/forestTileBack.png differ diff --git a/assets/style/farming/bg/forestTileFar.png b/assets/style/farming/bg/forestTileFar.png new file mode 100644 index 0000000..241e479 Binary files /dev/null and b/assets/style/farming/bg/forestTileFar.png differ diff --git a/assets/style/farming/bg/forestTileFront.png b/assets/style/farming/bg/forestTileFront.png new file mode 100644 index 0000000..e54f631 Binary files /dev/null and b/assets/style/farming/bg/forestTileFront.png differ diff --git a/assets/style/farming/bg/forestTileMid.png b/assets/style/farming/bg/forestTileMid.png new file mode 100644 index 0000000..b23afd2 Binary files /dev/null and b/assets/style/farming/bg/forestTileMid.png differ diff --git a/assets/style/farming/bg/grass.png b/assets/style/farming/bg/grass.png new file mode 100644 index 0000000..e05fb9b Binary files /dev/null and b/assets/style/farming/bg/grass.png differ diff --git a/assets/style/farming/bg/moon.png b/assets/style/farming/bg/moon.png new file mode 100644 index 0000000..d9a5ab7 Binary files /dev/null and b/assets/style/farming/bg/moon.png differ diff --git a/assets/style/farming/farmHouse.png b/assets/style/farming/farmHouse.png new file mode 100644 index 0000000..a07d787 Binary files /dev/null and b/assets/style/farming/farmHouse.png differ diff --git a/frig.frag b/frig.frag index f750f2d..6beb7b3 100644 --- a/frig.frag +++ b/frig.frag @@ -1,4 +1,4 @@ -#version 120 +#version 130 uniform sampler2D sampler; uniform int numLight; diff --git a/include/entities.hpp b/include/entities.hpp index e7864d0..f53f8e6 100644 --- a/include/entities.hpp +++ b/include/entities.hpp @@ -102,11 +102,7 @@ public: } void draw(){ - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, colorIndex); - glUseProgram(shaderProgram); - glUniform1i(glGetUniformLocation(shaderProgram, "sampler"), 0); - glEnable(GL_TEXTURE_2D); + //glEnable(GL_TEXTURE_2D); glColor3ub(255,255,255); glBegin(GL_QUADS); glTexCoord2f(.25*index.x, .125*index.y); glVertex2i(loc.x, loc.y); @@ -114,8 +110,8 @@ public: glTexCoord2f(.25*index.x, .125*index.y); glVertex2i(loc.x + width, loc.y + height); glTexCoord2f(.25*index.x, .125*index.y); glVertex2i(loc.x, loc.y + width); glEnd(); - glDisable(GL_TEXTURE_2D); - glUseProgram(0); + //glDisable(GL_TEXTURE_2D); + //glUseProgram(0); } bool kill(float delta){ duration -= delta; diff --git a/main.cpp b/main.cpp index 95d4e05..3b500f4 100644 --- a/main.cpp +++ b/main.cpp @@ -221,6 +221,9 @@ int main(int argc, char *argv[]){ return -1; } + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1); + // Run SDL_Quit when main returns atexit(SDL_Quit); @@ -338,6 +341,8 @@ int main(int argc, char *argv[]){ SDL_ShowCursor(SDL_DISABLE); + //glEnable(GL_CULL_FACE); + Texture::initColorIndex(); initEntity(); diff --git a/src/world.cpp b/src/world.cpp index bcd4f7a..625a33b 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -434,20 +434,20 @@ void World::draw(Player *p){ safeSetColorA( 255, 255, 255, weather == WorldWeather::Snowy ? 150 : 255 - worldShade * 4); glBegin( GL_QUADS ); - glTexCoord2i( 0, 0 ); glVertex2i( offset.x - SCREEN_WIDTH/2-5, SCREEN_HEIGHT ); - glTexCoord2i( 1, 0 ); glVertex2i( offset.x + SCREEN_WIDTH/2+5, SCREEN_HEIGHT ); - glTexCoord2i( 1, 1 ); glVertex2i( offset.x + SCREEN_WIDTH/2+5, 0 ); - glTexCoord2i( 0, 1 ); glVertex2i( offset.x - SCREEN_WIDTH/2-5, 0 ); + glTexCoord2i( 0, 0 ); glVertex2i( offset.x - SCREEN_WIDTH/2-5, offset.y + SCREEN_HEIGHT/2 ); + glTexCoord2i( 1, 0 ); glVertex2i( offset.x + SCREEN_WIDTH/2+5, offset.y + SCREEN_HEIGHT/2 ); + glTexCoord2i( 1, 1 ); glVertex2i( offset.x + SCREEN_WIDTH/2+5, offset.y - SCREEN_HEIGHT/2 ); + glTexCoord2i( 0, 1 ); glVertex2i( offset.x - SCREEN_WIDTH/2-5, offset.y - SCREEN_HEIGHT/2 ); glEnd(); bgTex->bindNext(); safeSetColorA( 255, 255, 255, worldShade * 4); glBegin( GL_QUADS ); - glTexCoord2i( 0, 0 ); glVertex2i( worldStart, SCREEN_HEIGHT ); - glTexCoord2i( 1, 0 ); glVertex2i( -worldStart, SCREEN_HEIGHT ); - glTexCoord2i( 1, 1 ); glVertex2i( -worldStart, 0 ); - glTexCoord2i( 0, 1 ); glVertex2i( worldStart, 0 ); + glTexCoord2i( 0, 0 ); glVertex2i( offset.x - SCREEN_WIDTH/2-5, offset.y + SCREEN_HEIGHT/2 ); + glTexCoord2i( 1, 0 ); glVertex2i( offset.x + SCREEN_WIDTH/2+5, offset.y + SCREEN_HEIGHT/2 ); + glTexCoord2i( 1, 1 ); glVertex2i( offset.x + SCREEN_WIDTH/2+5, offset.y - SCREEN_HEIGHT/2 ); + glTexCoord2i( 0, 1 ); glVertex2i( offset.x - SCREEN_WIDTH/2-5, offset.y - SCREEN_HEIGHT/2 ); glEnd(); glDisable( GL_TEXTURE_2D ); @@ -524,7 +524,15 @@ void World::draw(Player *p){ // draw particles and buildings - std::for_each( particles.begin(), particles.end(), [](Particles part) { if ( part.behind ) part.draw(); }); + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, colorIndex); + + glUniform1i(glGetUniformLocation(shaderProgram, "sampler"), 0); + glUseProgram(shaderProgram); + + std::for_each( particles.begin(), particles.end(), [](Particles part) { if ( part.behind ) part.draw(); }); + + glUseProgram(0); for ( auto &b : build ) b->draw(); @@ -671,8 +679,17 @@ void World::draw(Player *p){ * Draw remaining entities. */ + + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, colorIndex); + + glUniform1i(glGetUniformLocation(shaderProgram, "sampler"), 0); + glUseProgram(shaderProgram); + std::for_each( particles.begin(), particles.end(), [](Particles part) { if ( !part.behind ) part.draw(); }); + glUseProgram(0); + for ( auto &n : npc ) n->draw(); @@ -1383,9 +1400,18 @@ draw( Player *p ) /* * Draw all entities. */ + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, colorIndex); - for ( auto &part : particles ) - part.draw(); + glUniform1i(glGetUniformLocation(shaderProgram, "sampler"), 0); + glUseProgram(shaderProgram); + + std::for_each( particles.begin(), particles.end(), [](Particles &part) { part.draw(); }); + + glUseProgram(0); + + /*for ( auto &part : particles ) + part.draw();*/ for ( auto &e : entity ) e->draw(); @@ -1542,7 +1568,7 @@ loadWorldFromXMLNoSave( std::string path ) { loadedRight = false; } } else - abort(); + abort(); } else if ( name == "style" ) { tmp->setStyle(wxml->StrAttribute("folder")); tmp->setBackground((WorldBGType)wxml->UnsignedAttribute("background")); diff --git a/storyXML/0000_SpawnHill.xml b/storyXML/0000_SpawnHill.xml index 0a41197..7edd3b8 100644 --- a/storyXML/0000_SpawnHill.xml +++ b/storyXML/0000_SpawnHill.xml @@ -1,10 +1,12 @@ -