diff --git a/CrystalPoint.vcxproj.filters b/CrystalPoint.vcxproj.filters
index fd253f6..e894c14 100644
--- a/CrystalPoint.vcxproj.filters
+++ b/CrystalPoint.vcxproj.filters
@@ -69,11 +69,11 @@
Source Files\World
-
- Source Files
-
- Source Files
+ Source Files\World
+
+
+ Source Files\Object
diff --git a/HeightMap.cpp b/HeightMap.cpp
index e93fc7a..99e4924 100644
--- a/HeightMap.cpp
+++ b/HeightMap.cpp
@@ -131,6 +131,12 @@ float HeightMap::GetHeight(float x, float y)
return z.y;
}
+
+int HeightMap::GetSize()
+{
+ return height >= width ? height : width;
+}
+
void HeightMap::SetTexture(const std::string &file)
{
int bpp, width2, height2;
diff --git a/HeightMap.h b/HeightMap.h
index fe2e963..7ea9178 100644
--- a/HeightMap.h
+++ b/HeightMap.h
@@ -20,6 +20,7 @@ public:
void Draw();
float GetHeight(float x, float y);
+ int GetSize();
void SetTexture(const std::string &file);
std::vector vertices;
diff --git a/Skybox.cpp b/Skybox.cpp
index 18d1e50..1d268ab 100644
--- a/Skybox.cpp
+++ b/Skybox.cpp
@@ -8,9 +8,10 @@
enum{SKY_LEFT=0,SKY_BACK,SKY_RIGHT,SKY_FRONT,SKY_TOP,SKY_BOTTOM};
GLuint skybox[6];
-Skybox::Skybox(const float &size)
+Skybox::Skybox(const float &size, const std::string &folder)
{
this->size = size;
+ this->folder = folder;
}
Skybox::~Skybox()
@@ -20,12 +21,12 @@ Skybox::~Skybox()
void Skybox::init()
{
- skybox[SKY_LEFT] = loadTexture("skyboxes/water/left.png");
- skybox[SKY_BACK] = loadTexture("skyboxes/water/back.png");
- skybox[SKY_RIGHT] = loadTexture("skyboxes/water/right.png");
- skybox[SKY_FRONT] = loadTexture("skyboxes/water/front.png");
- skybox[SKY_TOP] = loadTexture("skyboxes/water/top.png");
- skybox[SKY_BOTTOM] = loadTexture("skyboxes/water/bottom.png");
+ skybox[SKY_LEFT] = loadTexture(folder + "left.png");
+ skybox[SKY_BACK] = loadTexture(folder + "back.png");
+ skybox[SKY_RIGHT] = loadTexture(folder + "right.png");
+ skybox[SKY_FRONT] = loadTexture(folder + "front.png");
+ skybox[SKY_TOP] = loadTexture(folder + "top.png");
+ skybox[SKY_BOTTOM] = loadTexture(folder + "bottom.png");
}
void Skybox::draw()
@@ -117,6 +118,7 @@ GLuint Skybox::loadTexture(const std::string & fileName) //load the filename na
{
int width, height, bpp;
+ stbi_set_flip_vertically_on_load(true);
unsigned char* imgData = stbi_load(fileName.c_str(), &width, &height, &bpp, 4);
GLuint num;
glGenTextures(1, &num);
diff --git a/Skybox.h b/Skybox.h
index 77f4f36..5b51fbb 100644
--- a/Skybox.h
+++ b/Skybox.h
@@ -3,11 +3,12 @@
class Skybox
{
-public:
- Skybox(const float &size);
- ~Skybox();
-
+private:
float size;
+ std::string folder;
+public:
+ Skybox(const float &size, const std::string &folder);
+ ~Skybox();
void init();
void draw();
diff --git a/World.cpp b/World.cpp
index 5aa603c..b0e090a 100644
--- a/World.cpp
+++ b/World.cpp
@@ -25,24 +25,18 @@ World::World(const std::string &fileName)
file.close();
//Check file
- if(v["world"].isNull() || v["world"]["heightmap"].isNull())
+ if(v["world"].isNull() || v["world"]["heightmap"].isNull() || v["world"]["skybox"].isNull())
std::cout << "Invalid world file: world - " << fileName << "\n";
+ if (v["world"]["object-templates"].isNull())
+ std::cout << "Invalid world file: object templates - " << fileName << "\n";
if (v["player"].isNull() || v["player"]["startposition"].isNull())
std::cout << "Invalid world file: player - " << fileName << "\n";
if (v["objects"].isNull())
std::cout << "Invalid world file: objects - " << fileName << "\n";
- if (v["world"]["object-templates"].isNull())
- std::cout << "Invalid world file: object templates - " << fileName << "\n";
- /*if(crystals)
-
- if(skybox)
-
- if(enemies)
- */
-
- skybox = new Skybox(15000.0f);
- skybox->init();
-
+ if (v["enemies"].isNull())
+ std::cout << "Invalid world file: enemies - " << fileName << "\n";
+ if (v["crystals"].isNull())
+ std::cout << "Invalid world file: crystals - " << fileName << "\n";
//Load object templates
for (auto objt : v["world"]["object-templates"])
@@ -58,6 +52,10 @@ World::World(const std::string &fileName)
//Generate heightmap for this world
heightmap = new HeightMap(v["world"]["heightmap"].asString(), this);
+ //Load skybox
+ skybox = new Skybox(15000.0f, v["world"]["skybox"].asString());
+ skybox->init();
+
//Map different texture to heightmap if available
if(!v["world"]["texture"].isNull())
heightmap->SetTexture(v["world"]["texture"].asString());
diff --git a/worlds/small.json b/worlds/small.json
index 66c7acc..901713b 100644
--- a/worlds/small.json
+++ b/worlds/small.json
@@ -1,6 +1,7 @@
{
"world": {
"heightmap": "worlds/small.png",
+ "skybox": "skyboxes/peaceful/",
"object-templates": [
{
"color": 100,