Fix image direction / load from JSON

This commit is contained in:
2016-06-09 12:22:40 +02:00
parent 69561794d8
commit a4373adc25
7 changed files with 37 additions and 28 deletions
+4 -4
View File
@@ -69,11 +69,11 @@
<ClCompile Include="Interface.cpp">
<Filter>Source Files\World</Filter>
</ClCompile>
<ClCompile Include="Crystal.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Skybox.cpp">
<Filter>Source Files</Filter>
<Filter>Source Files\World</Filter>
</ClCompile>
<ClCompile Include="Crystal.cpp">
<Filter>Source Files\Object</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
+6
View File
@@ -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;
+1
View File
@@ -20,6 +20,7 @@ public:
void Draw();
float GetHeight(float x, float y);
int GetSize();
void SetTexture(const std::string &file);
std::vector<Vertex> vertices;
+9 -7
View File
@@ -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);
+5 -4
View File
@@ -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();
+11 -13
View File
@@ -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());
+1
View File
@@ -1,6 +1,7 @@
{
"world": {
"heightmap": "worlds/small.png",
"skybox": "skyboxes/peaceful/",
"object-templates": [
{
"color": 100,