فهرست منبع

Fix image direction / load from JSON

Kenneth van Ewijk 9 سال پیش
والد
کامیت
a4373adc25
7فایلهای تغییر یافته به همراه36 افزوده شده و 27 حذف شده
  1. 4 4
      CrystalPoint.vcxproj.filters
  2. 6 0
      HeightMap.cpp
  3. 1 0
      HeightMap.h
  4. 9 7
      Skybox.cpp
  5. 4 3
      Skybox.h
  6. 11 13
      World.cpp
  7. 1 0
      worlds/small.json

+ 4 - 4
CrystalPoint.vcxproj.filters

@@ -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 - 0
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;

+ 1 - 0
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<Vertex> vertices;

+ 9 - 7
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);

+ 4 - 3
Skybox.h

@@ -3,12 +3,13 @@
  
 class Skybox
 {
+private:
+	float size;
+	std::string folder;
 public:
-	Skybox(const float &size);
+	Skybox(const float &size, const std::string &folder);
 	~Skybox();
 
-	float size;
-
 	void init();
 	void draw();
 	GLuint loadTexture(const std::string &fileName);

+ 11 - 13
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());

+ 1 - 0
worlds/small.json

@@ -1,6 +1,7 @@
 {
   "world": {
     "heightmap": "worlds/small.png",
+    "skybox": "skyboxes/peaceful/",
     "object-templates": [
       {
         "color": 100,