Reimplemented into newer develop version
@@ -163,6 +163,7 @@
|
||||
<ClCompile Include="Main.cpp" />
|
||||
<ClCompile Include="Model.cpp" />
|
||||
<ClCompile Include="Player.cpp" />
|
||||
<ClCompile Include="Skybox.cpp" />
|
||||
<ClCompile Include="Vector.cpp" />
|
||||
<ClCompile Include="Vertex.cpp" />
|
||||
<ClCompile Include="World.cpp" />
|
||||
@@ -181,6 +182,7 @@
|
||||
<ClInclude Include="Main.h" />
|
||||
<ClInclude Include="Model.h" />
|
||||
<ClInclude Include="Player.h" />
|
||||
<ClInclude Include="Skybox.h" />
|
||||
<ClInclude Include="stb_image.h" />
|
||||
<ClInclude Include="vector.h" />
|
||||
<ClInclude Include="Vertex.h" />
|
||||
|
||||
@@ -72,6 +72,9 @@
|
||||
<ClCompile Include="Crystal.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Skybox.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="World.h">
|
||||
@@ -125,6 +128,9 @@
|
||||
<ClInclude Include="Crystal.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Skybox.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="worlds\worlds.json">
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -91,6 +91,7 @@ void configureOpenGL()
|
||||
|
||||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_LIGHT0);
|
||||
//glEnable(GL_COLOR_MATERIAL);
|
||||
|
||||
glutSetCursor(GLUT_CURSOR_NONE);
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
#include "cmath"
|
||||
#include <GL/freeglut.h>
|
||||
|
||||
#include "stb_image.h"
|
||||
#include "Skybox.h"
|
||||
#include <string>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
|
||||
class Skybox
|
||||
{
|
||||
public:
|
||||
Skybox(const float &size);
|
||||
~Skybox();
|
||||
|
||||
float size;
|
||||
|
||||
void init();
|
||||
void draw();
|
||||
GLuint loadTexture(const std::string &fileName);
|
||||
};
|
||||
@@ -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<std::string, bool> 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)
|
||||
|
||||
@@ -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<Entity*> entities;
|
||||
std::vector<Enemy*> enemies;
|
||||
|
||||
|
After Width: | Height: | Size: 136 KiB |
|
After Width: | Height: | Size: 3.6 KiB |
|
After Width: | Height: | Size: 118 KiB |
|
After Width: | Height: | Size: 132 KiB |
|
After Width: | Height: | Size: 136 KiB |
|
After Width: | Height: | Size: 108 KiB |
|
After Width: | Height: | Size: 123 KiB |
|
After Width: | Height: | Size: 6.1 KiB |
|
After Width: | Height: | Size: 111 KiB |
|
After Width: | Height: | Size: 113 KiB |
|
After Width: | Height: | Size: 132 KiB |
|
After Width: | Height: | Size: 47 KiB |
|
After Width: | Height: | Size: 720 KiB |
|
After Width: | Height: | Size: 378 KiB |
|
After Width: | Height: | Size: 742 KiB |
|
After Width: | Height: | Size: 496 KiB |
|
After Width: | Height: | Size: 768 KiB |
|
After Width: | Height: | Size: 154 KiB |