Compare commits

..

No commits in common. "6b169a1c50228459a4e116ccdbce37514b3fadc0" and "097fe11f213b4e45c8f5d564491453a29be1c5a2" have entirely different histories.

17 changed files with 73 additions and 214 deletions

1
.gitignore vendored
View File

@ -1,5 +1,4 @@
XtreemMiner.cbp XtreemMiner.cbp
XtreemMiner.depend XtreemMiner.depend
XtreemMiner.layout
bin bin
obj obj

Binary file not shown.

Before

Width:  |  Height:  |  Size: 231 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 225 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 401 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 778 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 857 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 289 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 991 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 744 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 347 B

View File

@ -1,17 +1,10 @@
#ifndef BASE //#ifndef BASE
#define BASE //#define BASE
//#include "NodeRenderer.h" //#include "NodeRenderer.h"
//#include "MapBlock.h" #include "MapBlock.h"
class NodeManager; class NodeManager;
extern NodeManager nodeManager; extern NodeManager nodeManager;
extern NodeManager nodeManager1;
//#endif
struct Position2D
{
int x;
int z;
};
#endif

View File

@ -1,11 +0,0 @@
#include <cstdio>
class Logger
{
public:
void log(char* comp, char* message);
{
printf("Message: %c", message);
}
};

View File

@ -1,28 +1,30 @@
#ifndef MAPBLOCK_H #ifndef MAPBLOCK_H
#define MAPBLOCK_H #define MAPBLOCK_H
#include <cstdio>
#include "Base.h" #include "Base.h"
#include <math.h>
class NodeManager class NodeManager
{ {
public: public:
int blockX;
int blockZ;
NodeManager(int x, int z)
NodeManager()
{ {
} }
virtual ~NodeManager() virtual ~NodeManager()
{ {
} }
//8191
void printMapBlock()
{
for(int i = 0; i < 10536; i++)
{
printf("\n[%i] %i", i, mapBlock[i]);
}
}
void addNode(int id, int meta, int x, int y, int z) void addNode(int id, int meta, int x, int y, int z)
{ {
@ -39,36 +41,26 @@ class NodeManager
return x < 16 && z < 16 && x >= 0 && z >= 0 ? mapBlock[256 * y + z * 16 + x] : 0; return x < 16 && z < 16 && x >= 0 && z >= 0 ? mapBlock[256 * y + z * 16 + x] : 0;
} }
protected: protected:
private: private:
int mapBlock[65536]; int mapBlock[65536];
}; };
class BlockManager class Block
{
};
class BlockUtilities
{ {
public: public:
BlockUtilities() Block(int x, int z)
{ {
} }
static Position2D getBlockFromNodeCoordinates(int x, int z) int getBlockFromNodeCoordinates(int x, int z)
{ {
Position2D pos2d;
pos2d.x = floor(x / 16);
pos2d.z = floor(z / 16);
return pos2d;
} }
}; };
#endif #endif

View File

@ -4,6 +4,9 @@
#include "MapBlock.h" #include "MapBlock.h"
#include <GL/glut.h> #include <GL/glut.h>
class NodeRenderer class NodeRenderer
{ {
public: public:
@ -23,96 +26,96 @@ class NodeRenderer
// Front // Front
if(nodeManager.isAir(x, y, z - 1)) if(nodeManager.isAir(x, y, z - 1))
{ {
glTexCoord2f(.0F, .0F); glColor3f(1.0F, 1.0F, 1.0F);
glVertex3f(x + .0F, y + 1.0F, z + .0F); glVertex3f(x + .0F, y + 1.0F, z + .0F);
glTexCoord2f(1.0F, .0F); glColor3f(1.0F, 1.0F, 1.0F);
glVertex3f(x + 1.0F, y + 1.0F, z + .0F); glVertex3f(x + 1.0F, y + 1.0F, z + .0F);
glTexCoord2f(1.0F, 1.0F); glColor3f(1.0F, 1.0F, 1.0F);
glVertex3f(x + 1.0F, y + .0F, z + .0F); glVertex3f(x + 1.0F, y + .0F, z + .0F);
glTexCoord2f(.0F, 1.0F); glColor3f(1.0F, 1.0F, 1.0F);
glVertex3f(x + .0F, y + .0F, z + .0F); glVertex3f(x + .0F, y + .0F, z + .0F);
} }
// Back // Back
if(nodeManager.isAir(x, y, z + 1)) if(nodeManager.isAir(x, y, z + 1))
{ {
glTexCoord2f(.0F, .0F); glColor3f(.0F, 1.0F, 1.0F);
glVertex3f(x + .0F, y + 1.0F, z + 1.0F); glVertex3f(x + .0F, y + 1.0F, z + 1.0F);
glTexCoord2f(1.0F, .0F); glColor3f(.0F, 1.0F, 1.0F);
glVertex3f(x + 1.0F, y + 1.0F, z + 1.0F); glVertex3f(x + 1.0F, y + 1.0F, z + 1.0F);
glTexCoord2f(1.0F, 1.0F); glColor3f(.0F, 1.0F, 1.0F);
glVertex3f(x + 1.0F, y + .0F, z + 1.0F); glVertex3f(x + 1.0F, y + .0F, z + 1.0F);
glTexCoord2f(.0F, 1.0F); glColor3f(.0F, 1.0F, 1.0F);
glVertex3f(x + .0F, y + .0F, z + 1.0F); glVertex3f(x + .0F, y + .0F, z + 1.0F);
} }
// Right // Right
if(nodeManager.isAir(x + 1, y, z)) if(nodeManager.isAir(x + 1, y, z))
{ {
glTexCoord2f(1.0F, .0F); glColor3f(.0F, 1.0F, .0F);
glVertex3f(x + 1.0F, y + 1.0F, z + .0F); glVertex3f(x + 1.0F, y + 1.0F, z + .0F);
glTexCoord2f(1.0F, 1.0F); glColor3f(.0F, 1.0F, .0F);
glVertex3f(x + 1.0F, y + .0F, z + .0F); glVertex3f(x + 1.0F, y + .0F, z + .0F);
glTexCoord2f(.0F, 1.0F); glColor3f(.0F, 1.0F, .0F);
glVertex3f(x + 1.0F, y + .0F, z + 1.0F); glVertex3f(x + 1.0F, y + .0F, z + 1.0F);
glTexCoord2f(.0F, .0F); glColor3f(.0F, 1.0F, .0F);
glVertex3f(x + 1.0F, y + 1.0F, z + 1.0F); glVertex3f(x + 1.0F, y + 1.0F, z + 1.0F);
} }
// Left // Left
if(nodeManager.isAir(x - 1, y, z)) if(nodeManager.isAir(x - 1, y, z))
{ {
glTexCoord2f(1.0F, .0F); glColor3f(1.0F, .0F, .0F);
glVertex3f(x + .0F, y + 1.0F, z + .0F); glVertex3f(x + .0F, y + 1.0F, z + .0F);
glTexCoord2f(1.0F, 1.0F); glColor3f(1.0F, .0F, .0F);
glVertex3f(x + .0F, y + .0F, z + .0F); glVertex3f(x + .0F, y + .0F, z + .0F);
glTexCoord2f(.0F, 1.0F); glColor3f(1.0F, .0F, .0F);
glVertex3f(x + .0F, y + .0F, z + 1.0F); glVertex3f(x + .0F, y + .0F, z + 1.0F);
glTexCoord2f(.0F, .0F); glColor3f(1.0F, .0F, .0F);
glVertex3f(x + .0F, y + 1.0F, z + 1.0F); glVertex3f(x + .0F, y + 1.0F, z + 1.0F);
} }
// Bottom // Bottom
if(nodeManager.getNodeAt(x, y - 1, z) == 0) if(nodeManager.getNodeAt(x, y - 1, z) == 0)
{ {
glTexCoord2f(.0F, .0F); glColor3f(1.0F, 1.0F, .0F);
glVertex3f(x + 1.0F, y + .0F, z + .0F); glVertex3f(x + 1.0F, y + .0F, z + .0F);
glTexCoord2f(1.0F, .0F); glColor3f(1.0F, 1.0F, .0F);
glVertex3f(x + .0F, y + .0F, z + .0F); glVertex3f(x + .0F, y + .0F, z + .0F);
glTexCoord2f(1.0F, 1.0F); glColor3f(1.0F, 1.0F, .0F);
glVertex3f(x + .0F, y + .0F, z + 1.0F); glVertex3f(x + .0F, y + .0F, z + 1.0F);
glTexCoord2f(.0F, 1.0F); glColor3f(1.0F, 1.0F, .0F);
glVertex3f(x + 1.0F, y + .0F, z + 1.0F); glVertex3f(x + 1.0F, y + .0F, z + 1.0F);
} }
// Top // Top
if(nodeManager.getNodeAt(x, y + 1, z) == 0) if(nodeManager.getNodeAt(x, y + 1, z) == 0)
{ {
glTexCoord2f(.0F, .0F); glColor3f(.0F, .0F, 1.0F);
glVertex3f(x + 1.0F, y + 1.0F, z + .0F); glVertex3f(x + 1.0F, y + 1.0F, z + .0F);
glTexCoord2f(1.0F, .0F); glColor3f(.0F, .0F, 1.0F);
glVertex3f(x + .0F, y + 1.0F, z + .0F); glVertex3f(x + .0F, y + 1.0F, z + .0F);
glTexCoord2f(1.0F, 1.0F); glColor3f(.0F, .0F, 1.0F);
glVertex3f(x + .0F, y + 1.0F, z + 1.0F); glVertex3f(x + .0F, y + 1.0F, z + 1.0F);
glTexCoord2f(.0F, 1.0F); glColor3f(.0F, .0F, 1.0F);
glVertex3f(x + 1.0F, y + 1.0F, z + 1.0F); glVertex3f(x + 1.0F, y + 1.0F, z + 1.0F);
} }

View File

@ -1,17 +0,0 @@
class Node
{
public:
Node(int i, int j)
{
id = i;
textureIndex = j;
}
int getTextureIndexFromSide(int side)
{
return textureIndex;
}
private:
int id;
int textureIndex;
};

View File

@ -1,71 +1,6 @@
#define STBI_FAILURE_USERMSG
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h" #include "stb_image.h"
#include "Base.h" #ifndef TEXTURE_HANDLER
#define TEXTURE_HANDLER
//#ifndef TEXTURE_HANDLER #endif
//#define TEXTURE_HANDLER
class TextureHandler
{
private:
int width = -1;
int height = -1;
int comp = -1;
unsigned char* imageData;
unsigned char* imageData1;
public:
GLuint textures;
GLuint textures1;
unsigned char* loadTexture(char* filename)
{
return stbi_load(filename, &width, &height, &comp, 0);
}
void loadAllTextures()
{
int textureIndex = 0;
imageData = loadTexture("data/img/gold.png");
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glGenTextures(1, &textures);
glBindTexture(GL_TEXTURE_2D, textures);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 16, 16, 0, GL_RGB, GL_UNSIGNED_BYTE, imageData);
imageData1 = loadTexture("data/img/iron.png");
glGenTextures(1, &textures1);
glBindTexture(GL_TEXTURE_2D, textures1);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 16, 16, 0, GL_RGB, GL_UNSIGNED_BYTE, imageData1);
}
void getTextureForNode(int x, int y, int z)
{
if(nodeManager.getNodeAt(x, y, z) == 1)
{
glBindTexture(GL_TEXTURE_2D, textures);
}
else if(nodeManager.getNodeAt(x, y, z) == 2)
{
glBindTexture(GL_TEXTURE_2D, textures1);
}
}
};
//#endif

View File

@ -1,35 +1,33 @@
#include <stdlib.h> #include <stdlib.h>
#include <GL/glut.h> #include <GL/glut.h>
#include "MapBlock.h" #include "include/Base.h"
#include "Base.h"
#include "NodeRenderer.h" #include "NodeRenderer.h"
#include "TextureHandler.h"
#include <cstdio> #include <cstdio>
#include <random> #include <random>
NodeRenderer renderer; NodeRenderer renderer;
NodeManager nodeManager(0, 0); NodeManager nodeManager;
NodeManager nodeManager1(1, 0);
TextureHandler textureHandler;
GLfloat playerX = 0; GLfloat playerX = 0;
GLfloat playerY = -30; GLfloat playerY = -30;
GLfloat playerZ = -100; GLfloat playerZ = -100;
GLfloat playerRotX = 0; GLfloat playerRotX = 0;
void DisplayFunc()
void display()
{ {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity(); glLoadIdentity();
glTranslatef(playerX, playerY, playerZ);
glRotatef(playerRotX, .0F, 1.0F, .0F);
glEnable(GL_TEXTURE_2D); glTranslatef(playerX, playerY, playerZ);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); //glTranslatef(playerX, 0, - 1 - alpha / 4);
glRotatef(playerRotX, .0F, 1.0F, .0F);
//glRotatef(alpha * 1.1, 0, 1, 0);
glBegin(GL_QUADS); glBegin(GL_QUADS);
@ -39,29 +37,12 @@ void display()
{ {
for(int y = 0; y < 256; y++) for(int y = 0; y < 256; y++)
{ {
if(nodeManager.getNodeAt(x, y, z) > 0) if(nodeManager.getNodeAt(x, y, z) == 1)
{
textureHandler.getTextureForNode(x, y, z);
renderer.renderNode(x, y, z); renderer.renderNode(x, y, z);
}
} }
} }
} }
for(int x = 0; x < 16; x++)
{
for(int z = 0; z < 16; z++)
{
for(int y = 0; y < 256; y++)
{
if(nodeManager1.getNodeAt(x, y, z) > 0)
{
textureHandler.getTextureForNode(x, y, z);
renderer.renderNode(x, y, z);
}
}
}
}
glEnd(); glEnd();
@ -73,7 +54,7 @@ void display()
} }
void reshape(int width, int height) void ReshapeFunc(int width, int height)
{ {
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
@ -127,7 +108,10 @@ void KeyboardFunc(unsigned char key, int x, int y)
playerRotX += .8F; playerRotX += .8F;
} }
if(key == 'x')
{
nodeManager.printMapBlock();
}
if(key == 27) if(key == 27)
@ -139,10 +123,6 @@ void KeyboardFunc(unsigned char key, int x, int y)
} }
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
glutInit(&argc, argv); glutInit(&argc, argv);
@ -150,13 +130,10 @@ int main(int argc, char **argv)
glutInitWindowSize(800, 600); glutInitWindowSize(800, 600);
glutCreateWindow("XtreemNodes Engine - By MCL Software and Cube Software"); glutCreateWindow("XtreemNodes Engine - By MCL Software and Cube Software");
glClearColor(.2, .7, .8 , 255); glClearColor(.2, .7, .8, 255);
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
// Load textures
textureHandler.loadAllTextures();
@ -166,27 +143,15 @@ int main(int argc, char **argv)
{ {
for(int y = 0; y < 256; y++) for(int y = 0; y < 256; y++)
{ {
nodeManager.addNode(rand() % 3, 0, x, y, z); nodeManager.addNode(rand() % 2, 0, x, y, z);
//printf("\nGet node at: %i\n Is air: %i", nodeManager.getNodeAt(x, y + 1, z) == 0, nodeManager.isAir(x, y + 1, z));
}
}
}
for(int x = 0; x < 16; x++)
{
for(int z = 0; z < 16; z++)
{
for(int y = 0; y < 256; y++)
{
nodeManager1.addNode(rand() % 3, 0, x, y, z);
//printf("\nGet node at: %i\n Is air: %i", nodeManager.getNodeAt(x, y + 1, z) == 0, nodeManager.isAir(x, y + 1, z)); //printf("\nGet node at: %i\n Is air: %i", nodeManager.getNodeAt(x, y + 1, z) == 0, nodeManager.isAir(x, y + 1, z));
} }
} }
} }
glutDisplayFunc(&display); glutDisplayFunc(&DisplayFunc);
glutReshapeFunc(&reshape); glutReshapeFunc(&ReshapeFunc);
glutKeyboardFunc(&KeyboardFunc); glutKeyboardFunc(&KeyboardFunc);
glutMainLoop(); glutMainLoop();