diff --git a/CrystalPoint.vcxproj b/CrystalPoint.vcxproj
index a27143b..e225b3a 100644
--- a/CrystalPoint.vcxproj
+++ b/CrystalPoint.vcxproj
@@ -163,6 +163,7 @@
+
@@ -181,6 +182,7 @@
+
diff --git a/CrystalPoint.vcxproj.filters b/CrystalPoint.vcxproj.filters
index e0b56ed..fd253f6 100644
--- a/CrystalPoint.vcxproj.filters
+++ b/CrystalPoint.vcxproj.filters
@@ -72,6 +72,9 @@
Source Files
+
+ Source Files
+
@@ -125,6 +128,9 @@
Header Files
+
+ Header Files
+
diff --git a/Interface.cpp b/Interface.cpp
index 9a3d498..4a89725 100644
--- a/Interface.cpp
+++ b/Interface.cpp
@@ -77,8 +77,6 @@ void Interface::draw()
glColor4f(1.0f, 1.0f, 0.1f, 1.0);
glutBitmapString("Level: " + std::to_string(player->level), 490, 900);
-
-
int cw, ch, offset;
cw = 20;
ch = 50;
@@ -94,6 +92,9 @@ void Interface::draw()
glVertex2f(975 , ch / 2 + offset*i + ch*i);
glEnd();
}
+
+ glEnable(GL_LIGHTING);
+ glEnable(GL_DEPTH_TEST);
}
void Interface::update(float deltaTime)
diff --git a/Main.cpp b/Main.cpp
index d89aa26..413f30d 100644
--- a/Main.cpp
+++ b/Main.cpp
@@ -91,6 +91,7 @@ void configureOpenGL()
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
+ //glEnable(GL_COLOR_MATERIAL);
glutSetCursor(GLUT_CURSOR_NONE);
}
\ No newline at end of file
diff --git a/Skybox.cpp b/Skybox.cpp
new file mode 100644
index 0000000..18d1e50
--- /dev/null
+++ b/Skybox.cpp
@@ -0,0 +1,142 @@
+#include "cmath"
+#include
+
+#include "stb_image.h"
+#include "Skybox.h"
+#include
+
+enum{SKY_LEFT=0,SKY_BACK,SKY_RIGHT,SKY_FRONT,SKY_TOP,SKY_BOTTOM};
+GLuint skybox[6];
+
+Skybox::Skybox(const float &size)
+{
+ this->size = size;
+}
+
+Skybox::~Skybox()
+{
+ glDeleteTextures(6, &skybox[0]);
+}
+
+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");
+}
+
+void Skybox::draw()
+{
+ bool b1 = glIsEnabled(GL_TEXTURE_2D);
+ glDisable(GL_LIGHTING);
+ glDisable(GL_DEPTH_TEST);
+ glEnable(GL_TEXTURE_2D);
+ glDisable(GL_COLOR_MATERIAL);
+
+ glBindTexture(GL_TEXTURE_2D, skybox[SKY_BACK]);
+ glBegin(GL_QUADS);
+ glTexCoord2f(1,1);
+ glVertex3f(size / 2, size / 2, size / 2);
+ glTexCoord2f(0,1);
+ glVertex3f(-size / 2, size / 2, size / 2);
+ glTexCoord2f(0,0);
+ glVertex3f(-size / 2, -size / 2, size / 2);
+ glTexCoord2f(1,0);
+ glVertex3f(size / 2, -size / 2, size / 2);
+ glEnd();
+
+ glBindTexture(GL_TEXTURE_2D, skybox[SKY_LEFT]);
+ glBegin(GL_QUADS);
+ //left face
+ glTexCoord2f(1,1);
+ glVertex3f(-size / 2, size / 2, size / 2);
+ glTexCoord2f(0,1);
+ glVertex3f(-size / 2, size / 2, -size / 2);
+ glTexCoord2f(0,0);
+ glVertex3f(-size / 2, -size / 2, -size / 2);
+ glTexCoord2f(1,0);
+ glVertex3f(-size / 2, -size / 2, size / 2);
+ glEnd();
+ glBindTexture(GL_TEXTURE_2D, skybox[SKY_FRONT]);
+ glBegin(GL_QUADS);
+ //front face
+ glTexCoord2f(0, 1);
+ glVertex3f(size / 2, size / 2, -size / 2);
+ glTexCoord2f(1, 1);
+ glVertex3f(-size / 2, size / 2, -size / 2);
+ glTexCoord2f(1, 0);
+ glVertex3f(-size / 2, -size / 2, -size / 2);
+ glTexCoord2f(0, 0);
+ glVertex3f(size / 2, -size / 2, -size / 2);
+ glEnd();
+ glBindTexture(GL_TEXTURE_2D, skybox[SKY_RIGHT]);
+ glBegin(GL_QUADS);
+ //right face
+ glTexCoord2f(1, 1);
+ glVertex3f(size / 2, size / 2, -size / 2);
+ glTexCoord2f(0,1);
+ glVertex3f(size / 2, size / 2, size / 2);
+ glTexCoord2f(0,0);
+ glVertex3f(size / 2, -size / 2, size / 2);
+ glTexCoord2f(1, 0);
+ glVertex3f(size / 2, -size / 2, -size / 2);
+ glEnd();
+ glBindTexture(GL_TEXTURE_2D, skybox[SKY_TOP]);
+ glBegin(GL_QUADS); //top face
+ glTexCoord2f(0,0);
+ glVertex3f(size / 2, size / 2, size / 2);
+ glTexCoord2f(0,1);
+ glVertex3f(-size / 2, size / 2, size / 2);
+ glTexCoord2f(1,1);
+ glVertex3f(-size / 2, size / 2, -size / 2);
+ glTexCoord2f(1,0);
+ glVertex3f(size / 2, size / 2, -size / 2);
+ glEnd();
+ glBindTexture(GL_TEXTURE_2D, skybox[SKY_BOTTOM]);
+ glBegin(GL_QUADS);
+ //bottom face
+ glTexCoord2f(0,1);
+ glVertex3f(size / 2, -size / 2, size / 2);
+ glTexCoord2f(0,0);
+ glVertex3f(-size / 2, -size / 2, size / 2);
+ glTexCoord2f(1,0);
+ glVertex3f(-size / 2, -size / 2, -size / 2);
+ glTexCoord2f(1,1);
+ glVertex3f(size / 2, -size / 2, -size / 2);
+ glEnd();
+ glEnable(GL_LIGHTING); //turn everything back, which we turned on, and turn everything off, which we have turned on.
+ glEnable(GL_DEPTH_TEST);
+ if (!b1)
+ glDisable(GL_TEXTURE_2D);
+}
+
+GLuint Skybox::loadTexture(const std::string & fileName) //load the filename named texture
+{
+ int width, height, bpp;
+
+ unsigned char* imgData = stbi_load(fileName.c_str(), &width, &height, &bpp, 4);
+ GLuint num;
+ glGenTextures(1, &num);
+ glBindTexture(GL_TEXTURE_2D, num);
+
+ glTexImage2D(GL_TEXTURE_2D,
+ 0, //level
+ GL_RGBA, //internal format
+ width, //width
+ height, //height
+ 0, //border
+ GL_RGBA, //data format
+ GL_UNSIGNED_BYTE, //data type
+ imgData); //data
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
+
+ stbi_image_free(imgData);
+ return num;
+}
+
diff --git a/Skybox.h b/Skybox.h
new file mode 100644
index 0000000..77f4f36
--- /dev/null
+++ b/Skybox.h
@@ -0,0 +1,15 @@
+#pragma once
+#include
+
+class Skybox
+{
+public:
+ Skybox(const float &size);
+ ~Skybox();
+
+ float size;
+
+ void init();
+ void draw();
+ GLuint loadTexture(const std::string &fileName);
+};
diff --git a/World.cpp b/World.cpp
index ed1b343..5aa603c 100644
--- a/World.cpp
+++ b/World.cpp
@@ -33,6 +33,16 @@ World::World(const std::string &fileName)
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();
+
//Load object templates
for (auto objt : v["world"]["object-templates"])
@@ -149,7 +159,8 @@ World::World(const std::string &fileName)
World::~World()
{
- //delete heightmap;
+ delete heightmap;
+ delete skybox;
}
std::pair World::getObjectFromValue(int val)
@@ -177,6 +188,8 @@ void World::draw()
float lightAmbient[4] = { 0.2, 0.2, 0.2, 1 };
glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbient);
+ skybox->draw();
+
heightmap->Draw();
for (auto &enemy : enemies)
diff --git a/World.h b/World.h
index cce4e3b..fc17d69 100644
--- a/World.h
+++ b/World.h
@@ -7,6 +7,7 @@
#include "LevelObject.h"
#include "Interface.h"
#include "Crystal.h"
+#include "Skybox.h"
class Entity;
@@ -18,6 +19,7 @@ private:
Player* player;
HeightMap* heightmap;
Interface* interface;
+ Skybox* skybox;
std::vector entities;
std::vector enemies;
diff --git a/skyboxes/peaceful/back.png b/skyboxes/peaceful/back.png
new file mode 100644
index 0000000..d45a424
Binary files /dev/null and b/skyboxes/peaceful/back.png differ
diff --git a/skyboxes/peaceful/bottom.png b/skyboxes/peaceful/bottom.png
new file mode 100644
index 0000000..5db7212
Binary files /dev/null and b/skyboxes/peaceful/bottom.png differ
diff --git a/skyboxes/peaceful/front.png b/skyboxes/peaceful/front.png
new file mode 100644
index 0000000..85f1c79
Binary files /dev/null and b/skyboxes/peaceful/front.png differ
diff --git a/skyboxes/peaceful/left.png b/skyboxes/peaceful/left.png
new file mode 100644
index 0000000..eee545d
Binary files /dev/null and b/skyboxes/peaceful/left.png differ
diff --git a/skyboxes/peaceful/right.png b/skyboxes/peaceful/right.png
new file mode 100644
index 0000000..5ff5a2e
Binary files /dev/null and b/skyboxes/peaceful/right.png differ
diff --git a/skyboxes/peaceful/top.png b/skyboxes/peaceful/top.png
new file mode 100644
index 0000000..8e799f0
Binary files /dev/null and b/skyboxes/peaceful/top.png differ
diff --git a/skyboxes/test/back.png b/skyboxes/test/back.png
new file mode 100644
index 0000000..7cc0a30
Binary files /dev/null and b/skyboxes/test/back.png differ
diff --git a/skyboxes/test/bottom.png b/skyboxes/test/bottom.png
new file mode 100644
index 0000000..f742d17
Binary files /dev/null and b/skyboxes/test/bottom.png differ
diff --git a/skyboxes/test/front.png b/skyboxes/test/front.png
new file mode 100644
index 0000000..af353ce
Binary files /dev/null and b/skyboxes/test/front.png differ
diff --git a/skyboxes/test/left.png b/skyboxes/test/left.png
new file mode 100644
index 0000000..568e58c
Binary files /dev/null and b/skyboxes/test/left.png differ
diff --git a/skyboxes/test/right.png b/skyboxes/test/right.png
new file mode 100644
index 0000000..9443f8c
Binary files /dev/null and b/skyboxes/test/right.png differ
diff --git a/skyboxes/test/top.png b/skyboxes/test/top.png
new file mode 100644
index 0000000..0dbc574
Binary files /dev/null and b/skyboxes/test/top.png differ
diff --git a/skyboxes/water/back.png b/skyboxes/water/back.png
new file mode 100644
index 0000000..d813596
Binary files /dev/null and b/skyboxes/water/back.png differ
diff --git a/skyboxes/water/bottom.png b/skyboxes/water/bottom.png
new file mode 100644
index 0000000..66436b9
Binary files /dev/null and b/skyboxes/water/bottom.png differ
diff --git a/skyboxes/water/front.png b/skyboxes/water/front.png
new file mode 100644
index 0000000..4e24463
Binary files /dev/null and b/skyboxes/water/front.png differ
diff --git a/skyboxes/water/left.png b/skyboxes/water/left.png
new file mode 100644
index 0000000..46cc0db
Binary files /dev/null and b/skyboxes/water/left.png differ
diff --git a/skyboxes/water/right.png b/skyboxes/water/right.png
new file mode 100644
index 0000000..70a00f1
Binary files /dev/null and b/skyboxes/water/right.png differ
diff --git a/skyboxes/water/top.png b/skyboxes/water/top.png
new file mode 100644
index 0000000..970b815
Binary files /dev/null and b/skyboxes/water/top.png differ