Compare commits
49 Commits
6b169a1c50
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 7e7a73f9b6 | |||
| 45d324a9ec | |||
| 7342507fe8 | |||
| cec9ecb561 | |||
| afc842baae | |||
| 7fa3d76fe1 | |||
| 3de9e9af4b | |||
| 9eeb2f89b2 | |||
| 76e38e0606 | |||
| 190e2c7445 | |||
| 6aa1dec552 | |||
| 76c7e1808c | |||
| 1215e7d8a5 | |||
| c3fa504c29 | |||
| 4efefa976a | |||
| dcac2713f6 | |||
| ac2c3b5c79 | |||
| 3cd61d369a | |||
| 76d0a7b0a7 | |||
| 360614e231 | |||
| d4c3fdca39 | |||
| 31348c7b29 | |||
| ea818914bc | |||
| fbe3bbd55e | |||
| 70830e5014 | |||
| 46cc1be435 | |||
| cc7dfbc03d | |||
| 39a256cb49 | |||
| 04ad3afe7d | |||
| 5471f17bad | |||
| 37676b72be | |||
| a0bec8bfc5 | |||
| 3aa203bac9 | |||
| 4c76fd1144 | |||
| 1d1aad04cf | |||
| 922826da0b | |||
| 1965b97c19 | |||
| 171c890aa4 | |||
| aa58a2945e | |||
| 13828992d4 | |||
| 8365b148d0 | |||
| 8cde72f632 | |||
| 6b05eaf331 | |||
| 0d9da1cc25 | |||
| 12933729b9 | |||
| 1a26c07604 | |||
| c72cdc23a4 | |||
| fd496dd085 | |||
| 62a93d5d44 |
5
.gitignore
vendored
@@ -1,5 +0,0 @@
|
|||||||
XtreemMiner.cbp
|
|
||||||
XtreemMiner.depend
|
|
||||||
XtreemMiner.layout
|
|
||||||
bin
|
|
||||||
obj
|
|
||||||
7
Camera.cpp
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
#include "include/Camera.h"
|
||||||
|
|
||||||
|
const glm::mat4& Camera::get_view()
|
||||||
|
{
|
||||||
|
const glm::mat4& matrix = glm::lookAt(glm::vec3(0, 10, 0), glm::vec3(0, 1, 0), glm::vec3(0, 1, 0));
|
||||||
|
return matrix;
|
||||||
|
}
|
||||||
51
GUI.cpp
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
#include "GUI.h"
|
||||||
|
|
||||||
|
// Code contributed by Kacperks
|
||||||
|
// COMMENTED OUT BECAUSE IT DOESN'T WORK!
|
||||||
|
/*
|
||||||
|
Button::Button(sf::Image* normal, sf::Image* clicked, std::string words, Position2D location) {
|
||||||
|
this->normal.SetImage(*normal);
|
||||||
|
this->clicked.SetImage(*clicked);
|
||||||
|
this->currentSpr=&this->normal;
|
||||||
|
current =false;
|
||||||
|
this->normal.SetPosition(location);
|
||||||
|
this->clicked.SetPosition(location);
|
||||||
|
String.SetText(words);
|
||||||
|
String.SetPosition(location.x+3,location.y+3);
|
||||||
|
String.SetSize(14);
|
||||||
|
}
|
||||||
|
void Button::checkClick (sf::Vector2f mousePos)
|
||||||
|
{
|
||||||
|
if (mousePos.x>currentSpr->GetPosition().x && mousePos.x<(currentSpr->GetPosition().x + currentSpr->GetSize().x)) {
|
||||||
|
if(mousePos.y>currentSpr->GetPosition().y && mousePos.y<(currentSpr->GetPosition().y + currentSpr->GetSize().y)) {
|
||||||
|
setState(!current);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Button::setState(bool which)
|
||||||
|
{
|
||||||
|
current = which;
|
||||||
|
if (current) {
|
||||||
|
currentSpr=&clicked;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
currentSpr=&normal;
|
||||||
|
}
|
||||||
|
void Button::setText(std::string words)
|
||||||
|
{
|
||||||
|
String.SetText(words);
|
||||||
|
}
|
||||||
|
bool Button::getVar()
|
||||||
|
{
|
||||||
|
return current;
|
||||||
|
}
|
||||||
|
sf::Sprite* Button::getSprite()
|
||||||
|
{
|
||||||
|
return currentSpr;
|
||||||
|
}
|
||||||
|
|
||||||
|
sf::String * Button::getText()
|
||||||
|
{
|
||||||
|
return &String;
|
||||||
|
}*/
|
||||||
7
LICENSE.TXT
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
Copyright (c) 2022-2023 MCL and CubeSoftware
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
139
LevelGenerator.cpp
Normal file
@@ -0,0 +1,139 @@
|
|||||||
|
#include "LevelGenerator.h"
|
||||||
|
#include "Base.h"
|
||||||
|
#include <time.h>
|
||||||
|
#include <random>
|
||||||
|
|
||||||
|
FastNoiseLite perlin, os, cellular;
|
||||||
|
int seed = 138;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
LevelGenerator::LevelGenerator()
|
||||||
|
{
|
||||||
|
perlin.SetSeed(seed);
|
||||||
|
perlin.SetNoiseType(FastNoiseLite::NoiseType_Perlin);
|
||||||
|
perlin.SetFrequency(.01F);
|
||||||
|
|
||||||
|
os.SetSeed(seed);
|
||||||
|
os.SetNoiseType(FastNoiseLite::NoiseType_OpenSimplex2);
|
||||||
|
os.SetFrequency(.01F);
|
||||||
|
|
||||||
|
cellular.SetSeed(seed);
|
||||||
|
cellular.SetNoiseType(FastNoiseLite::NoiseType_Cellular);
|
||||||
|
cellular.SetFrequency(.1F);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Change seed midgame - not for production use
|
||||||
|
void LevelGenerator::setSeed()
|
||||||
|
{
|
||||||
|
perlin.SetSeed(time(0));
|
||||||
|
os.SetSeed(time(0));
|
||||||
|
cellular.SetSeed(time(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
void LevelGenerator::generateBlock()
|
||||||
|
{
|
||||||
|
for(int x = 0; x < 256; x++)
|
||||||
|
{
|
||||||
|
for(int z = 0; z < 256; z++)
|
||||||
|
{
|
||||||
|
for(int y = 0; y < 256; y++)
|
||||||
|
{
|
||||||
|
blockManager.addNode(0, 0, x, y, z);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
for(int x = 0; x < 256; x++)
|
||||||
|
{
|
||||||
|
for(int z = 0; z < 256; z++)
|
||||||
|
{
|
||||||
|
float cX = (float)x;
|
||||||
|
float cZ = (float)z;
|
||||||
|
for(int y = 0; y < 48 * abs(perlin.GetNoise(cX, cZ)) / 2 + abs(cellular.GetNoise(cX, cZ)) * 2 + abs(os.GetNoise(cX, cZ)) * 4 + 10; y++)
|
||||||
|
{
|
||||||
|
blockManager.addNode(1, 0, x, y, z);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
terraformBlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
void LevelGenerator::terraformBlock()
|
||||||
|
{
|
||||||
|
for(int x = 0; x < 256; x++)
|
||||||
|
{
|
||||||
|
for(int z = 0; z < 256; z++)
|
||||||
|
{
|
||||||
|
for(int y = 0; y < 256; y++)
|
||||||
|
{
|
||||||
|
int currentNode = blockManager.getNodeAt(x, y, z);
|
||||||
|
if(currentNode != 0)
|
||||||
|
{
|
||||||
|
if(y == 15 && (blockManager.getNodeAt(x, y + 1, z) == 0 || blockManager.getNodeAt(x, y + 1, z) == 20))
|
||||||
|
{
|
||||||
|
currentNode = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
else if(y < 15)
|
||||||
|
{
|
||||||
|
currentNode = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
blockManager.addNode(currentNode, 0, x, y, z);
|
||||||
|
}
|
||||||
|
else if(y < 16)
|
||||||
|
{
|
||||||
|
blockManager.addNode(20, 0, x, y, z); // Water
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
populate();
|
||||||
|
}
|
||||||
|
|
||||||
|
void LevelGenerator::populate()
|
||||||
|
{
|
||||||
|
for(int counter = 0; counter < 30; counter++)
|
||||||
|
{
|
||||||
|
int x = rand() % 256;
|
||||||
|
int z = rand() % 256;
|
||||||
|
|
||||||
|
for(int y = 10; y < 256; y++)
|
||||||
|
{
|
||||||
|
if(blockManager.getNodeAt(x, y, z) == 0)
|
||||||
|
{
|
||||||
|
if(blockManager.getNodeAt(x, y - 1, z) == 20)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
counter -= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int y1 = y; y1 < y + 6; y1++)
|
||||||
|
{
|
||||||
|
blockManager.addNode(12, 0, x, y1, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int i = 0; i < 3; i++)
|
||||||
|
{
|
||||||
|
for(int j = 0; j < 3; j++)
|
||||||
|
{
|
||||||
|
for(int k = 0; k < 3; k++)
|
||||||
|
{
|
||||||
|
blockManager.addNode(13, 0, x + i - 1, y + j + 6, z + k - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
77
MapBlock.cpp
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
#include "MapBlock.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int mapBlock[65536];
|
||||||
|
|
||||||
|
MapBlock::MapBlock()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void BlockManager::addNode(int id, int meta, int x, int y, int z)
|
||||||
|
{
|
||||||
|
Position2D block = BlockUtilities::getBlockFromNodeCoordinates(x, z);
|
||||||
|
|
||||||
|
int localX = x - block.x * 16;
|
||||||
|
int localZ = z - block.z * 16;
|
||||||
|
|
||||||
|
mapBlocks[block.x][block.z].mapBlock[256 * y + localZ * 16 + localX] = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
MapBlock mapBlocks[16][16];
|
||||||
|
|
||||||
|
BlockManager::BlockManager()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int BlockManager::getNodeAt(int x, int y, int z)
|
||||||
|
{
|
||||||
|
// Math explanation for future reference:
|
||||||
|
// The x and z coordinates need to be have block.[AXIS] * 16 subtracted from them
|
||||||
|
// so that the coordinates passed to the function are local block coordinates instead
|
||||||
|
// of global node coordinates (e.g. 1, and not 17)
|
||||||
|
|
||||||
|
if(x < 0 || y < 0 || z < 0)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Position2D block = BlockUtilities::getBlockFromNodeCoordinates(x, z);
|
||||||
|
|
||||||
|
int localX = x - block.x * 16;
|
||||||
|
int localZ = z - block.z * 16;
|
||||||
|
|
||||||
|
return mapBlocks[block.x][block.z].mapBlock[256 * y + localZ * 16 + localX];
|
||||||
|
}
|
||||||
|
|
||||||
|
bool BlockManager::isAir(int x, int y, int z)
|
||||||
|
{
|
||||||
|
return getNodeAt(x, y, z) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool BlockManager::isNodeClear(int x, int y, int z)
|
||||||
|
{
|
||||||
|
if(getNodeAt(x, y, z) == 0)
|
||||||
|
return true;
|
||||||
|
if(getNodeAt(x, y, z) == 20)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
BlockUtilities::BlockUtilities()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Position2D BlockUtilities::getBlockFromNodeCoordinates(int x, int z)
|
||||||
|
{
|
||||||
|
Position2D pos2d;
|
||||||
|
//pos2d.x = floor(x / 16);
|
||||||
|
//pos2d.z = floor(z / 16);
|
||||||
|
pos2d.x = x >> 4;
|
||||||
|
pos2d.z = z >> 4;
|
||||||
|
return pos2d;
|
||||||
|
}
|
||||||
13
README.TXT
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
===============
|
||||||
|
XtreemNodes 0.3
|
||||||
|
(2023-08-27)
|
||||||
|
===============
|
||||||
|
|
||||||
|
XtreemNodes is a modern 3-D game engine by MCL Software made in collaboration with Cube Software.
|
||||||
|
|
||||||
|
The project was started on 2022-10-15 by a mysterious man sitting at his desk at 3 a.m.
|
||||||
|
|
||||||
|
==================================
|
||||||
|
How to build on Windows with MSYS2
|
||||||
|
==================================
|
||||||
|
Download OpenGL, SFML, and mingw-w64 using Pacman and build the source files
|
||||||
19
TitleMenu.cpp
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#include "include/TitleMenu.h"
|
||||||
|
#include <GL/glut.h>
|
||||||
|
|
||||||
|
void TitleMenu::renderGUI()
|
||||||
|
{
|
||||||
|
glTranslatef(.0F, .0F, .0F);
|
||||||
|
|
||||||
|
glColor3f(1.0F, .0F, .0F);
|
||||||
|
|
||||||
|
glBegin(GL_TRIANGLES);
|
||||||
|
|
||||||
|
glVertex2f(.0F, -500.0F);
|
||||||
|
|
||||||
|
glVertex2f(.0F, 500.0F);
|
||||||
|
|
||||||
|
glVertex2f(500.0F, .0F);
|
||||||
|
|
||||||
|
glEnd();
|
||||||
|
}
|
||||||
|
Before Width: | Height: | Size: 231 B |
BIN
data/img/bro.png
Normal file
|
After Width: | Height: | Size: 4.2 KiB |
|
Before Width: | Height: | Size: 225 B |
|
Before Width: | Height: | Size: 401 B |
|
Before Width: | Height: | Size: 778 B After Width: | Height: | Size: 778 B |
|
Before Width: | Height: | Size: 857 B |
|
Before Width: | Height: | Size: 289 B |
|
Before Width: | Height: | Size: 991 B |
BIN
data/img/oak.png
|
Before Width: | Height: | Size: 744 B |
|
Before Width: | Height: | Size: 347 B |
BIN
data/img/texturemap.png
Normal file
|
After Width: | Height: | Size: 19 KiB |
@@ -1,17 +1,19 @@
|
|||||||
#ifndef BASE
|
#ifndef BASE
|
||||||
#define BASE
|
#define BASE
|
||||||
|
|
||||||
//#include "NodeRenderer.h"
|
#include "MapBlock.h"
|
||||||
//#include "MapBlock.h"
|
|
||||||
|
class NodeManager;
|
||||||
class NodeManager;
|
class BlockManager;
|
||||||
extern NodeManager nodeManager;
|
|
||||||
extern NodeManager nodeManager1;
|
extern NodeManager nodeManager;
|
||||||
|
extern BlockManager blockManager;
|
||||||
|
|
||||||
struct Position2D
|
extern float light;
|
||||||
{
|
|
||||||
int x;
|
/*struct Position2D
|
||||||
int z;
|
{
|
||||||
};
|
int x;
|
||||||
#endif
|
int z;
|
||||||
|
};*/
|
||||||
|
#endif
|
||||||
|
|||||||
19
include/Camera.h
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#include <glm/glm.hpp>
|
||||||
|
#include <glm/ext/matrix_transform.hpp>
|
||||||
|
|
||||||
|
class Camera
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Camera() = default;
|
||||||
|
virtual ~Camera()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
const glm::mat4& get_view();
|
||||||
|
const glm::mat4& get_projection();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
const glm::mat4& matrix;
|
||||||
|
glm::mat4 m_view, m_projection;
|
||||||
|
};
|
||||||
|
|
||||||
2586
include/FastNoiseLite.h
Normal file
26
include/GUI.h
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
#ifndef GUI
|
||||||
|
#define GUI
|
||||||
|
#include "Base.h"
|
||||||
|
#include <SFML/Main.hpp>
|
||||||
|
#include <SFML/Graphics.hpp>
|
||||||
|
|
||||||
|
class Button
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Button(sf::Image* normal, sf::Image* clicked, std::string text, Position2D location);
|
||||||
|
void checkClick(Position2D);
|
||||||
|
void setState(bool state);
|
||||||
|
void setText(std::string);
|
||||||
|
bool getVar();
|
||||||
|
sf::Sprite* getSprite();
|
||||||
|
sf::String* getText();
|
||||||
|
|
||||||
|
private:
|
||||||
|
sf::Sprite normal;
|
||||||
|
sf::Sprite clicked;
|
||||||
|
sf::Sprite* currentSpr;
|
||||||
|
sf::String String;
|
||||||
|
bool current;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
21
include/LevelGenerator.h
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
#ifndef LEVELGENERATOR
|
||||||
|
#define LEVELGENERATOR
|
||||||
|
#include "FastNoiseLite.h"
|
||||||
|
|
||||||
|
class LevelGenerator
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
LevelGenerator();
|
||||||
|
void setSeed();
|
||||||
|
void generateBlock();
|
||||||
|
void terraformBlock();
|
||||||
|
void populate();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
private:
|
||||||
|
FastNoiseLite perlin, os, cellular;
|
||||||
|
int seed = 138; // 1338, 1337. 138 are good ones
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
||||||
|
|
||||||
class Logger
|
class Logger
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void log(char* comp, char* message);
|
void log(char* comp, char* message);
|
||||||
{
|
{
|
||||||
printf("Message: %c", message);
|
printf("Message: %c", message);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,74 +1,38 @@
|
|||||||
#ifndef MAPBLOCK_H
|
#ifndef MAPBLOCK
|
||||||
#define MAPBLOCK_H
|
#define MAPBLOCK
|
||||||
#include "Base.h"
|
#include "Base.h"
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include <cstdio>
|
||||||
|
|
||||||
|
class MapBlock
|
||||||
|
{
|
||||||
|
public:
|
||||||
class NodeManager
|
int mapBlock[65536];
|
||||||
{
|
MapBlock();
|
||||||
public:
|
};
|
||||||
int blockX;
|
|
||||||
int blockZ;
|
class BlockManager
|
||||||
|
{
|
||||||
NodeManager(int x, int z)
|
public:
|
||||||
{
|
MapBlock mapBlocks[16][16];
|
||||||
|
BlockManager();
|
||||||
|
int getNodeAt(int x, int y, int z);
|
||||||
}
|
void addNode(int id, int meta, int x, int y, int z);
|
||||||
|
bool isAir(int x, int y, int z);
|
||||||
virtual ~NodeManager()
|
bool isNodeClear(int x, int y, int z);
|
||||||
{
|
};
|
||||||
|
|
||||||
}
|
struct Position2D
|
||||||
|
{
|
||||||
void addNode(int id, int meta, int x, int y, int z)
|
int x;
|
||||||
{
|
int z;
|
||||||
mapBlock[256 * y + z * 16 + x] = id;
|
};
|
||||||
}
|
|
||||||
|
class BlockUtilities
|
||||||
bool isAir(int x, int y, int z)
|
{
|
||||||
{
|
public:
|
||||||
return getNodeAt(x, y, z) == 0;
|
BlockUtilities();
|
||||||
}
|
static Position2D getBlockFromNodeCoordinates(int x, int z);
|
||||||
|
};
|
||||||
int getNodeAt(int x, int y, int z)
|
|
||||||
{
|
#endif
|
||||||
return x < 16 && z < 16 && x >= 0 && z >= 0 ? mapBlock[256 * y + z * 16 + x] : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
private:
|
|
||||||
int mapBlock[65536];
|
|
||||||
};
|
|
||||||
|
|
||||||
class BlockManager
|
|
||||||
{
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
class BlockUtilities
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
BlockUtilities()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static Position2D getBlockFromNodeCoordinates(int x, int z)
|
|
||||||
{
|
|
||||||
Position2D pos2d;
|
|
||||||
pos2d.x = floor(x / 16);
|
|
||||||
pos2d.z = floor(z / 16);
|
|
||||||
return pos2d;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|||||||
@@ -1,129 +1,285 @@
|
|||||||
#ifndef NODERENDERER_H
|
#ifndef NODERENDERER_H
|
||||||
#define NODERENDERER_H
|
#define NODERENDERER_H
|
||||||
#include "Base.h"
|
#include "Base.h"
|
||||||
#include "MapBlock.h"
|
#include "MapBlock.h"
|
||||||
#include <GL/glut.h>
|
#include <GL/glut.h>
|
||||||
|
|
||||||
class NodeRenderer
|
class NodeRenderer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
NodeRenderer()
|
NodeRenderer()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~NodeRenderer()
|
virtual ~NodeRenderer()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int renderNode(int x, int y, int z)
|
int renderNode(int x, int y, int z, int tex)
|
||||||
{
|
{
|
||||||
glBegin(GL_QUADS);
|
Position2D block = BlockUtilities::getBlockFromNodeCoordinates(x, z); // The block the node at (x, y, z) is in
|
||||||
// Front
|
Position2D textureCoordinate;
|
||||||
if(nodeManager.isAir(x, y, z - 1))
|
textureCoordinate.x = tex - (16 * floor(tex / 16));
|
||||||
{
|
textureCoordinate.z = floor(tex / 16) + 1;
|
||||||
glTexCoord2f(.0F, .0F);
|
|
||||||
glVertex3f(x + .0F, y + 1.0F, z + .0F);
|
|
||||||
|
//glColor3f(light, light, light);
|
||||||
glTexCoord2f(1.0F, .0F);
|
|
||||||
glVertex3f(x + 1.0F, y + 1.0F, z + .0F);
|
glBegin(GL_TRIANGLES);
|
||||||
|
// Front
|
||||||
glTexCoord2f(1.0F, 1.0F);
|
if(blockManager.isAir(x, y, z - 1))
|
||||||
glVertex3f(x + 1.0F, y + .0F, z + .0F);
|
{
|
||||||
|
/*glTexCoord2f(.0F, .0F);
|
||||||
glTexCoord2f(.0F, 1.0F);
|
glVertex3f(x + .0F, y + 1.0F, z + .0F);
|
||||||
glVertex3f(x + .0F, y + .0F, z + .0F);
|
|
||||||
}
|
glTexCoord2f(.0625F * textureCoordinate, .0F);
|
||||||
|
glVertex3f(x + 1.0F, y + 1.0F, z + .0F);
|
||||||
// Back
|
|
||||||
if(nodeManager.isAir(x, y, z + 1))
|
//glColor3f(.6F, .6F, .6F); // Bottom vertices
|
||||||
{
|
glTexCoord2f(.0625F * textureCoordinate, .0625F * textureCoordinate);
|
||||||
glTexCoord2f(.0F, .0F);
|
glVertex3f(x + 1.0F, y + .0F, z + .0F);
|
||||||
glVertex3f(x + .0F, y + 1.0F, z + 1.0F);
|
|
||||||
|
//glColor3f(1.0F, 1.0F, 1.0F);
|
||||||
glTexCoord2f(1.0F, .0F);
|
glTexCoord2f(.0F, .0625F * textureCoordinate);
|
||||||
glVertex3f(x + 1.0F, y + 1.0F, z + 1.0F);
|
glVertex3f(x + .0F, y + .0F, z + .0F);*/
|
||||||
|
|
||||||
glTexCoord2f(1.0F, 1.0F);
|
|
||||||
glVertex3f(x + 1.0F, y + .0F, z + 1.0F);
|
glTexCoord2f(.0625F * (textureCoordinate.x - 1), .0625F * (textureCoordinate.z - 1));
|
||||||
|
glVertex3f(x + .0F, y + 1.0F, z + .0F);
|
||||||
glTexCoord2f(.0F, 1.0F);
|
|
||||||
glVertex3f(x + .0F, y + .0F, z + 1.0F);
|
glTexCoord2f(.0625F * textureCoordinate.x, .0625F * (textureCoordinate.z - 1));
|
||||||
}
|
glVertex3f(x + 1.0F, y + 1.0F, z + .0F);
|
||||||
|
|
||||||
// Right
|
//glColor3f(.6F, .6F, .6F); // Bottom vertices
|
||||||
if(nodeManager.isAir(x + 1, y, z))
|
glTexCoord2f(.0625F * textureCoordinate.x, .0625F * textureCoordinate.z);
|
||||||
{
|
glVertex3f(x + 1.0F, y + .0F, z + .0F);
|
||||||
glTexCoord2f(1.0F, .0F);
|
|
||||||
glVertex3f(x + 1.0F, y + 1.0F, z + .0F);
|
|
||||||
|
//glColor3f(1.0F, 1.0F, 1.0F);
|
||||||
glTexCoord2f(1.0F, 1.0F);
|
glTexCoord2f(.0625F * (textureCoordinate.x - 1), .0625F * textureCoordinate.z);
|
||||||
glVertex3f(x + 1.0F, y + .0F, z + .0F);
|
glVertex3f(x + .0F, y + .0F, z + .0F);
|
||||||
|
|
||||||
glTexCoord2f(.0F, 1.0F);
|
glTexCoord2f(.0625F * (textureCoordinate.x - 1), .0625F * (textureCoordinate.z - 1));
|
||||||
glVertex3f(x + 1.0F, y + .0F, z + 1.0F);
|
glVertex3f(x + .0F, y + 1.0F, z + .0F);
|
||||||
|
|
||||||
glTexCoord2f(.0F, .0F);
|
//glColor3f(.6F, .6F, .6F); // Bottom vertices
|
||||||
glVertex3f(x + 1.0F, y + 1.0F, z + 1.0F);
|
glTexCoord2f(.0625F * textureCoordinate.x, .0625F * textureCoordinate.z);
|
||||||
}
|
glVertex3f(x + 1.0F, y + .0F, z + .0F);
|
||||||
|
}
|
||||||
// Left
|
|
||||||
if(nodeManager.isAir(x - 1, y, z))
|
// Back
|
||||||
{
|
if(blockManager.isAir(x, y, z + 1))
|
||||||
glTexCoord2f(1.0F, .0F);
|
{
|
||||||
glVertex3f(x + .0F, y + 1.0F, z + .0F);
|
/*glTexCoord2f(.0F, .0F);
|
||||||
|
glVertex3f(x + .0F, y + 1.0F, z + 1.0F);
|
||||||
glTexCoord2f(1.0F, 1.0F);
|
|
||||||
glVertex3f(x + .0F, y + .0F, z + .0F);
|
glTexCoord2f(.0625F * textureCoordinate, .0F);
|
||||||
|
glVertex3f(x + 1.0F, y + 1.0F, z + 1.0F);
|
||||||
glTexCoord2f(.0F, 1.0F);
|
|
||||||
glVertex3f(x + .0F, y + .0F, z + 1.0F);
|
//glColor3f(.6F, .6F, .6F);
|
||||||
|
glTexCoord2f(.0625F * textureCoordinate, .0625F * textureCoordinate);
|
||||||
glTexCoord2f(.0F, .0F);
|
glVertex3f(x + 1.0F, y + .0F, z + 1.0F);
|
||||||
glVertex3f(x + .0F, y + 1.0F, z + 1.0F);
|
|
||||||
}
|
//glColor3f(1.0F, 1.0F, 1.0F);
|
||||||
|
glTexCoord2f(.0F, .0625F * textureCoordinate);
|
||||||
// Bottom
|
glVertex3f(x + .0F, y + .0F, z + 1.0F);*/
|
||||||
if(nodeManager.getNodeAt(x, y - 1, z) == 0)
|
|
||||||
{
|
|
||||||
glTexCoord2f(.0F, .0F);
|
glTexCoord2f(.0625F * (textureCoordinate.x - 1), .0625F * (textureCoordinate.z - 1));
|
||||||
glVertex3f(x + 1.0F, y + .0F, z + .0F);
|
glVertex3f(x + .0F, y + 1.0F, z + 1.0F);
|
||||||
|
|
||||||
glTexCoord2f(1.0F, .0F);
|
glTexCoord2f(.0625F * textureCoordinate.x, .0625F * (textureCoordinate.z - 1));
|
||||||
glVertex3f(x + .0F, y + .0F, z + .0F);
|
glVertex3f(x + 1.0F, y + 1.0F, z + 1.0F);
|
||||||
|
|
||||||
glTexCoord2f(1.0F, 1.0F);
|
//glColor3f(.6F, .6F, .6F);
|
||||||
glVertex3f(x + .0F, y + .0F, z + 1.0F);
|
glTexCoord2f(.0625F * textureCoordinate.x, .0625F * textureCoordinate.z);
|
||||||
|
glVertex3f(x + 1.0F, y + .0F, z + 1.0F);
|
||||||
glTexCoord2f(.0F, 1.0F);
|
|
||||||
glVertex3f(x + 1.0F, y + .0F, z + 1.0F);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Top
|
|
||||||
if(nodeManager.getNodeAt(x, y + 1, z) == 0)
|
|
||||||
{
|
glTexCoord2f(.0625F * (textureCoordinate.x - 1), .0625F * (textureCoordinate.z - 1));
|
||||||
glTexCoord2f(.0F, .0F);
|
glVertex3f(x + .0F, y + 1.0F, z + 1.0F);
|
||||||
glVertex3f(x + 1.0F, y + 1.0F, z + .0F);
|
|
||||||
|
//glColor3f(1.0F, 1.0F, 1.0F);
|
||||||
glTexCoord2f(1.0F, .0F);
|
glTexCoord2f(.0625F * (textureCoordinate.x - 1), .0625F * textureCoordinate.z);
|
||||||
glVertex3f(x + .0F, y + 1.0F, z + .0F);
|
glVertex3f(x + .0F, y + .0F, z + 1.0F);
|
||||||
|
|
||||||
glTexCoord2f(1.0F, 1.0F);
|
//glColor3f(.6F, .6F, .6F);
|
||||||
glVertex3f(x + .0F, y + 1.0F, z + 1.0F);
|
glTexCoord2f(.0625F * textureCoordinate.x, .0625F * textureCoordinate.z);
|
||||||
|
glVertex3f(x + 1.0F, y + .0F, z + 1.0F);
|
||||||
glTexCoord2f(.0F, 1.0F);
|
}
|
||||||
glVertex3f(x + 1.0F, y + 1.0F, z + 1.0F);
|
|
||||||
}
|
// Right
|
||||||
|
if(blockManager.isAir(x + 1, y, z))
|
||||||
glEnd();
|
{
|
||||||
return 1;
|
/*glTexCoord2f(.0625F * textureCoordinate, .0F);
|
||||||
}
|
glVertex3f(x + 1.0F, y + 1.0F, z + .0F);
|
||||||
|
|
||||||
protected:
|
//glColor3f(.6F, .6F, .6F);
|
||||||
|
glTexCoord2f(.0625F * textureCoordinate, 1.0F);
|
||||||
private:
|
glVertex3f(x + 1.0F, y + .0F, z + .0F);
|
||||||
|
|
||||||
};
|
//glColor3f(1.0F, 1.0F, 1.0F);
|
||||||
|
glTexCoord2f(.0F, .0625F * textureCoordinate);
|
||||||
#endif
|
glVertex3f(x + 1.0F, y + .0F, z + 1.0F);
|
||||||
|
|
||||||
|
glTexCoord2f(.0F, .0F);
|
||||||
|
glVertex3f(x + 1.0F, y + 1.0F, z + 1.0F);*/
|
||||||
|
|
||||||
|
glTexCoord2f(.0625F * textureCoordinate.x, .0625F * (textureCoordinate.z - 1));
|
||||||
|
glVertex3f(x + 1.0F, y + 1.0F, z + .0F);
|
||||||
|
|
||||||
|
//glColor3f(.6F, .6F, .6F);
|
||||||
|
glTexCoord2f(.0625F * textureCoordinate.x, .0625F * textureCoordinate.z);
|
||||||
|
glVertex3f(x + 1.0F, y + .0F, z + .0F);
|
||||||
|
|
||||||
|
//glColor3f(1.0F, 1.0F, 1.0F);
|
||||||
|
glTexCoord2f(.0625F * (textureCoordinate.x - 1), .0625F * textureCoordinate.z);
|
||||||
|
glVertex3f(x + 1.0F, y + .0F, z + 1.0F);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
glTexCoord2f(.0625F * (textureCoordinate.x - 1), .0625F * (textureCoordinate.z - 1));
|
||||||
|
glVertex3f(x + 1.0F, y + 1.0F, z + 1.0F);
|
||||||
|
|
||||||
|
glTexCoord2f(.0625F * textureCoordinate.x, .0625F * (textureCoordinate.z - 1));
|
||||||
|
glVertex3f(x + 1.0F, y + 1.0F, z + .0F);
|
||||||
|
|
||||||
|
//glColor3f(1.0F, 1.0F, 1.0F);
|
||||||
|
glTexCoord2f(.0625F * (textureCoordinate.x - 1), .0625F * textureCoordinate.z);
|
||||||
|
glVertex3f(x + 1.0F, y + .0F, z + 1.0F);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Left
|
||||||
|
if(blockManager.isAir(x - 1, y, z))
|
||||||
|
{
|
||||||
|
/*glTexCoord2f(.0625F * textureCoordinate, .0F);
|
||||||
|
glVertex3f(x + .0F, y + 1.0F, z + .0F);
|
||||||
|
|
||||||
|
//glColor3f(.6F, .6F, .6F);
|
||||||
|
glTexCoord2f(.0625F * textureCoordinate, .0625F * textureCoordinate);
|
||||||
|
glVertex3f(x + .0F, y + .0F, z + .0F);
|
||||||
|
|
||||||
|
glTexCoord2f(.0F, .0625F * textureCoordinate);
|
||||||
|
glVertex3f(x + .0F, y + .0F, z + 1.0F);
|
||||||
|
//glColor3f(1.0F, 1.0F, 1.0F);
|
||||||
|
|
||||||
|
glTexCoord2f(.0F, .0F);
|
||||||
|
glVertex3f(x + .0F, y + 1.0F, z + 1.0F);*/
|
||||||
|
|
||||||
|
glTexCoord2f(.0625F * textureCoordinate.x, .0625F * (textureCoordinate.z - 1));
|
||||||
|
glVertex3f(x + .0F, y + 1.0F, z + .0F);
|
||||||
|
|
||||||
|
//glColor3i(100, 100, 100);
|
||||||
|
glTexCoord2f(.0625F * textureCoordinate.x, .0625F * textureCoordinate.z);
|
||||||
|
glVertex3f(x + .0F, y + .0F, z + .0F);
|
||||||
|
|
||||||
|
//glColor3i(255, 255, 255);
|
||||||
|
glTexCoord2f(.0625F * (textureCoordinate.x - 1), .0625F * textureCoordinate.z);
|
||||||
|
glVertex3f(x + .0F, y + .0F, z + 1.0F);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
glTexCoord2f(.0625F * (textureCoordinate.x - 1), .0625F * (textureCoordinate.z - 1));
|
||||||
|
glVertex3f(x + .0F, y + 1.0F, z + 1.0F);
|
||||||
|
|
||||||
|
glTexCoord2f(.0625F * textureCoordinate.x, .0625F * (textureCoordinate.z - 1));
|
||||||
|
glVertex3f(x + .0F, y + 1.0F, z + .0F);
|
||||||
|
|
||||||
|
//glColor3f(1.0F, 1.0F, 1.0F);
|
||||||
|
glTexCoord2f(.0625F * (textureCoordinate.x - 1), .0625F * textureCoordinate.z);
|
||||||
|
glVertex3f(x + .0F, y + .0F, z + 1.0F);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bottom
|
||||||
|
//printf("\n\nx: %i, y: %i, z: %i, VALUE: %s", x, y, z, blockManager.isAir(x, y - 1, z) ? "true" : "false");
|
||||||
|
if(y > 0 && blockManager.isAir(x, y - 1, z))
|
||||||
|
{
|
||||||
|
//printf("\nWUT? x: %i, y: %i, z: %i, VALUE: %s", x, y, z, blockManager.isAir(x, y - 1, z) ? "true" : "false");
|
||||||
|
/*glTexCoord2f(.0F, .0F);
|
||||||
|
glVertex3f(x + 1.0F, y + .0F, z + .0F);
|
||||||
|
|
||||||
|
glTexCoord2f(.0625F * textureCoordinate, .0F);
|
||||||
|
glVertex3f(x + .0F, y + .0F, z + .0F);
|
||||||
|
|
||||||
|
glTexCoord2f(.0625F * textureCoordinate, .0625F * textureCoordinate);
|
||||||
|
glVertex3f(x + .0F, y + .0F, z + 1.0F);
|
||||||
|
|
||||||
|
glTexCoord2f(.0F, .0625F * textureCoordinate);
|
||||||
|
glVertex3f(x + 1.0F, y + .0F, z + 1.0F);*/
|
||||||
|
|
||||||
|
glTexCoord2f(.0F, .0F);
|
||||||
|
glVertex3f(x + 1.0F, y + .0F, z + .0F);
|
||||||
|
|
||||||
|
glTexCoord2f(.0625F * textureCoordinate.x, .0F);
|
||||||
|
glVertex3f(x + .0F, y + .0F, z + .0F);
|
||||||
|
|
||||||
|
glTexCoord2f(.0625F * textureCoordinate.x, .0625F * textureCoordinate.z);
|
||||||
|
glVertex3f(x + .0F, y + .0F, z + 1.0F);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
glTexCoord2f(.0F, .0625F * textureCoordinate.x);
|
||||||
|
glVertex3f(x + 1.0F, y + .0F, z + 1.0F);
|
||||||
|
|
||||||
|
glTexCoord2f(.0F, .0F);
|
||||||
|
glVertex3f(x + 1.0F, y + .0F, z + .0F);
|
||||||
|
|
||||||
|
glTexCoord2f(.0625F * textureCoordinate.x, .0625F * textureCoordinate.z);
|
||||||
|
glVertex3f(x + .0F, y + .0F, z + 1.0F);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Top
|
||||||
|
if(blockManager.isNodeClear(x, y + 1, z))
|
||||||
|
{
|
||||||
|
/*glTexCoord2f(.0F, .0F);
|
||||||
|
glVertex3f(x + 1.0F, y + 1.0F, z + .0F);
|
||||||
|
|
||||||
|
glTexCoord2f(.0625F * textureCoordinate, .0F);
|
||||||
|
glVertex3f(x + .0F, y + 1.0F, z + .0F);
|
||||||
|
|
||||||
|
glTexCoord2f(.0625F * textureCoordinate, .0625F * textureCoordinate);
|
||||||
|
glVertex3f(x + .0F, y + 1.0F, z + 1.0F);
|
||||||
|
|
||||||
|
glTexCoord2f(.0F, .0625F * textureCoordinate);
|
||||||
|
glVertex3f(x + 1.0F, y + 1.0F, z + 1.0F);*/
|
||||||
|
|
||||||
|
glTexCoord2f(.0625F * (textureCoordinate.x - 1), .0625F * (textureCoordinate.z - 1));
|
||||||
|
glVertex3f(x + 1.0F, y + 1.0F, z + .0F);
|
||||||
|
|
||||||
|
glTexCoord2f(.0625F * textureCoordinate.x, .0625F * (textureCoordinate.z - 1));
|
||||||
|
glVertex3f(x + .0F, y + 1.0F, z + .0F);
|
||||||
|
|
||||||
|
glTexCoord2f(.0625F * textureCoordinate.x, .0625F * textureCoordinate.z);
|
||||||
|
glVertex3f(x + .0F, y + 1.0F, z + 1.0F);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
glTexCoord2f(.0625F * (textureCoordinate.x - 1), .0625F * textureCoordinate.z);
|
||||||
|
glVertex3f(x + 1.0F, y + 1.0F, z + 1.0F);
|
||||||
|
|
||||||
|
glTexCoord2f(.0625F * textureCoordinate.x, .0625F * textureCoordinate.z);
|
||||||
|
glVertex3f(x + .0F, y + 1.0F, z + 1.0F);
|
||||||
|
|
||||||
|
glTexCoord2f(.0625F * (textureCoordinate.x - 1), .0625F * (textureCoordinate.z - 1));
|
||||||
|
glVertex3f(x + 1.0F, y + 1.0F, z + .0F);
|
||||||
|
}
|
||||||
|
|
||||||
|
glEnd();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
class Node
|
class Node
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Node(int i, int j)
|
Node(int i, int j)
|
||||||
{
|
{
|
||||||
id = i;
|
id = i;
|
||||||
textureIndex = j;
|
textureIndex = j;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getTextureIndexFromSide(int side)
|
int getTextureIndexFromSide(int side)
|
||||||
{
|
{
|
||||||
return textureIndex;
|
return textureIndex;
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
int id;
|
int id;
|
||||||
int textureIndex;
|
int textureIndex;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,71 +1,77 @@
|
|||||||
#define STBI_FAILURE_USERMSG
|
#define STBI_FAILURE_USERMSG
|
||||||
#define STB_IMAGE_IMPLEMENTATION
|
#define STB_IMAGE_IMPLEMENTATION
|
||||||
#include "stb_image.h"
|
#include "stb_image.h"
|
||||||
#include "Base.h"
|
#include "Base.h"
|
||||||
|
|
||||||
|
|
||||||
//#ifndef TEXTURE_HANDLER
|
#ifndef TEXTURE_HANDLER
|
||||||
//#define TEXTURE_HANDLER
|
#define TEXTURE_HANDLER
|
||||||
class TextureHandler
|
class TextureHandler
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
int width = -1;
|
int width = -1;
|
||||||
int height = -1;
|
int height = -1;
|
||||||
int comp = -1;
|
int comp = -1;
|
||||||
unsigned char* imageData;
|
unsigned char* imageData;
|
||||||
unsigned char* imageData1;
|
unsigned char* imageData1;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GLuint textures;
|
GLuint texture;
|
||||||
GLuint textures1;
|
unsigned char* loadTexture(char* filename)
|
||||||
unsigned char* loadTexture(char* filename)
|
{
|
||||||
{
|
return stbi_load(filename, &width, &height, &comp, 0);
|
||||||
return stbi_load(filename, &width, &height, &comp, 0);
|
}
|
||||||
}
|
|
||||||
|
void loadAllTextures()
|
||||||
void loadAllTextures()
|
{
|
||||||
{
|
int textureIndex = 0;
|
||||||
int textureIndex = 0;
|
|
||||||
imageData = loadTexture("data/img/gold.png");
|
imageData = loadTexture("data/img/texturemap.png");
|
||||||
|
glGenTextures(1, &texture);
|
||||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
glBindTexture(GL_TEXTURE_2D, texture);
|
||||||
|
|
||||||
glGenTextures(1, &textures);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||||
glBindTexture(GL_TEXTURE_2D, textures);
|
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_WRAP_S, GL_REPEAT);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, imageData);
|
||||||
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);
|
int getTextureForNode(int x, int y, int z)
|
||||||
|
{
|
||||||
imageData1 = loadTexture("data/img/iron.png");
|
//Position2D block = BlockUtilities::getBlockFromNodeCoordinates(x, z);
|
||||||
glGenTextures(1, &textures1);
|
if(blockManager.getNodeAt(x, y, z) == 1)
|
||||||
glBindTexture(GL_TEXTURE_2D, textures1);
|
{
|
||||||
|
return 1;
|
||||||
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);
|
else if(blockManager.getNodeAt(x, y, z) == 2)
|
||||||
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);
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
void getTextureForNode(int x, int y, int z)
|
else if(blockManager.getNodeAt(x, y, z) == 3)
|
||||||
{
|
{
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
if(nodeManager.getNodeAt(x, y, z) == 1)
|
|
||||||
{
|
else if(blockManager.getNodeAt(x, y, z) == 12)
|
||||||
glBindTexture(GL_TEXTURE_2D, textures);
|
{
|
||||||
}
|
return 81;
|
||||||
|
}
|
||||||
else if(nodeManager.getNodeAt(x, y, z) == 2)
|
|
||||||
{
|
else if(blockManager.getNodeAt(x, y, z) == 13)
|
||||||
glBindTexture(GL_TEXTURE_2D, textures1);
|
{
|
||||||
}
|
return 113;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
else if(blockManager.getNodeAt(x, y, z) == 20)
|
||||||
};
|
{
|
||||||
|
return 17;
|
||||||
//#endif
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|||||||
15
include/TitleMenu.h
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
#ifndef TITLEMENU
|
||||||
|
#define TITLEMENU
|
||||||
|
|
||||||
|
class TitleMenu
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
TitleMenu()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void renderGUI();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
24
include/Utilities.h
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#ifndef UTILITIES
|
||||||
|
#define UTILITIES
|
||||||
|
|
||||||
|
|
||||||
|
class Utilities
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Utilities()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static float degToRad(int degrees)
|
||||||
|
{
|
||||||
|
return 3.14 / 180 * degrees; // Only the first three digits of pi
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
private:
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
15796
include/stb_image.h
433
main.cpp
@@ -1,195 +1,238 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <GL/glut.h>
|
#include <GL/glut.h>
|
||||||
|
#include "Utilities.h"
|
||||||
#include "MapBlock.h"
|
#include "LevelGenerator.h"
|
||||||
#include "Base.h"
|
//#include "MapBlock.h"
|
||||||
#include "NodeRenderer.h"
|
//#include "Base.h"
|
||||||
#include "TextureHandler.h"
|
#include "NodeRenderer.h"
|
||||||
#include <cstdio>
|
#include "TextureHandler.h"
|
||||||
#include <random>
|
#include <math.h>
|
||||||
|
#include <cstdio>
|
||||||
NodeRenderer renderer;
|
#include "include/Camera.h"
|
||||||
NodeManager nodeManager(0, 0);
|
#include <random>
|
||||||
NodeManager nodeManager1(1, 0);
|
#include <glm/ext/matrix_transform.hpp>
|
||||||
TextureHandler textureHandler;
|
#include <SFML/Window.hpp>
|
||||||
|
#include "include/TitleMenu.h"
|
||||||
GLfloat playerX = 0;
|
|
||||||
GLfloat playerY = -30;
|
NodeRenderer renderer;
|
||||||
GLfloat playerZ = -100;
|
BlockManager blockManager;
|
||||||
GLfloat playerRotX = 0;
|
LevelGenerator levelGen;
|
||||||
|
TextureHandler textureHandler;
|
||||||
|
|
||||||
|
GLfloat playerX = 2.5F;
|
||||||
void display()
|
GLfloat playerY = 20.0F;
|
||||||
{
|
GLfloat playerZ = 1.5F;
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
GLfloat playerRotX = 0;
|
||||||
glLoadIdentity();
|
GLfloat playerRotY = 0;
|
||||||
|
float light = 1.0F;
|
||||||
glTranslatef(playerX, playerY, playerZ);
|
sf::Vector2i oldMousePos;
|
||||||
glRotatef(playerRotX, .0F, 1.0F, .0F);
|
|
||||||
|
TitleMenu title;
|
||||||
glEnable(GL_TEXTURE_2D);
|
|
||||||
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
|
void display()
|
||||||
|
{
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
glBegin(GL_QUADS);
|
glLoadIdentity();
|
||||||
for(int x = 0; x < 16; x++)
|
|
||||||
{
|
|
||||||
for(int z = 0; z < 16; z++)
|
//glRotatef(playerRotX, 1.0F, .0F, .0F);
|
||||||
{
|
//glRotatef(playerRotY, .0F, 1.0F, .0F);
|
||||||
for(int y = 0; y < 256; y++)
|
Camera* camera;
|
||||||
{
|
|
||||||
if(nodeManager.getNodeAt(x, y, z) > 0)
|
const glm::mat4& matrix = glm::lookAt(glm::vec3(playerX, playerY, playerZ), glm::vec3(playerX - cos(glm::radians(playerRotY)), playerY - playerRotX, playerZ + sin(glm::radians(playerRotY))), glm::vec3(0, 1, 0));
|
||||||
{
|
|
||||||
textureHandler.getTextureForNode(x, y, z);
|
//https://glm.g-truc.net/0.9.9/api/a00668.html#gaa64aa951a0e99136bba9008d2b59c78e
|
||||||
renderer.renderNode(x, y, z);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
}
|
//TODO transform
|
||||||
}
|
//glMatrixMode(GL_PROJECTION);
|
||||||
}
|
glLoadMatrixf(&matrix[0][0]);
|
||||||
}
|
//glTranslatef(playerX, playerY, playerZ);
|
||||||
|
//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||||
for(int x = 0; x < 16; x++)
|
|
||||||
{
|
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||||
for(int z = 0; z < 16; z++)
|
|
||||||
{
|
|
||||||
for(int y = 0; y < 256; y++)
|
|
||||||
{
|
|
||||||
if(nodeManager1.getNodeAt(x, y, z) > 0)
|
for(int x = 0; x < 256; x++)
|
||||||
{
|
{
|
||||||
textureHandler.getTextureForNode(x, y, z);
|
for(int y = 0; y < 80; y++)
|
||||||
renderer.renderNode(x, y, z);
|
{
|
||||||
}
|
for(int z = 0; z < 256; z++)
|
||||||
}
|
{
|
||||||
}
|
if(blockManager.getNodeAt(x, y, z) > 0)
|
||||||
}
|
{
|
||||||
|
renderer.renderNode(x, y, z, textureHandler.getTextureForNode(x, y, z));
|
||||||
glEnd();
|
}
|
||||||
|
}
|
||||||
glFlush();
|
}
|
||||||
glutSwapBuffers();
|
}
|
||||||
|
|
||||||
|
//title.renderGUI();
|
||||||
glutPostRedisplay();
|
|
||||||
}
|
glFlush();
|
||||||
|
glutSwapBuffers();
|
||||||
|
}
|
||||||
void reshape(int width, int height)
|
|
||||||
{
|
|
||||||
glMatrixMode(GL_PROJECTION);
|
void reshape(int width, int height)
|
||||||
|
{
|
||||||
glLoadIdentity();
|
glMatrixMode(GL_PROJECTION);
|
||||||
gluPerspective(20, width / (float) height, 5, 150);
|
|
||||||
glViewport(0, 0, width, height);
|
glLoadIdentity();
|
||||||
|
gluPerspective(50, width / (float) height, .1F, 512.0F);
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glViewport(0, 0, width, height);
|
||||||
glutPostRedisplay();
|
|
||||||
}
|
glMatrixMode(GL_MODELVIEW);
|
||||||
|
glutPostRedisplay();
|
||||||
void KeyboardFunc(unsigned char key, int x, int y)
|
}
|
||||||
{
|
|
||||||
if(key == 'a')
|
int movementAngle = 0;
|
||||||
{
|
int angularVel = 1;
|
||||||
playerX += .8F;
|
|
||||||
}
|
void updateTimer(int time)
|
||||||
|
{
|
||||||
if(key == 'd')
|
// Movement
|
||||||
{
|
if(sf::Keyboard::isKeyPressed(sf::Keyboard::W))
|
||||||
playerX -= .8F;
|
{
|
||||||
}
|
movementAngle = 0;
|
||||||
|
}
|
||||||
if(key == 'w')
|
|
||||||
{
|
else if(sf::Keyboard::isKeyPressed(sf::Keyboard::S))
|
||||||
playerZ += .8F;
|
{
|
||||||
}
|
movementAngle = 180; // 200 grads
|
||||||
|
}
|
||||||
if(key == 's')
|
|
||||||
{
|
if(sf::Keyboard::isKeyPressed(sf::Keyboard::A))
|
||||||
playerZ -= .8F;
|
{
|
||||||
}
|
movementAngle = 90;
|
||||||
|
}
|
||||||
if(key == 'q')
|
|
||||||
{
|
else if(sf::Keyboard::isKeyPressed(sf::Keyboard::D))
|
||||||
playerY += .1F;
|
{
|
||||||
}
|
movementAngle = 270;
|
||||||
|
}
|
||||||
if(key == 'e')
|
|
||||||
{
|
if(sf::Keyboard::isKeyPressed(sf::Keyboard::W) || sf::Keyboard::isKeyPressed(sf::Keyboard::S))
|
||||||
playerY -= .1F;
|
{
|
||||||
}
|
int oldX = playerX;
|
||||||
|
int oldZ = playerZ;
|
||||||
if(key == 'f')
|
playerX = playerX - cos(glm::radians(playerRotY + movementAngle)) * angularVel;
|
||||||
{
|
playerZ = playerZ + sin(glm::radians(playerRotY + movementAngle)) * angularVel;
|
||||||
playerRotX -= .8F;
|
if(blockManager.getNodeAt(playerX, playerY, playerZ) != 0)
|
||||||
}
|
{
|
||||||
|
playerX = oldX;
|
||||||
if(key == 'h')
|
playerZ = oldZ;
|
||||||
{
|
}
|
||||||
playerRotX += .8F;
|
}
|
||||||
}
|
|
||||||
|
if(sf::Keyboard::isKeyPressed(sf::Keyboard::LShift))
|
||||||
|
{
|
||||||
|
if(blockManager.getNodeAt(playerX, playerY - 4, playerZ) == 0)
|
||||||
|
{
|
||||||
if(key == 27)
|
playerY -= .8;
|
||||||
{
|
}
|
||||||
exit(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Space))
|
||||||
}
|
{
|
||||||
|
playerY += .8;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rotation
|
||||||
|
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
|
||||||
|
{
|
||||||
int main(int argc, char **argv)
|
playerRotY -= 1.8;
|
||||||
{
|
}
|
||||||
glutInit(&argc, argv);
|
|
||||||
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
|
else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
|
||||||
glutInitWindowSize(800, 600);
|
{
|
||||||
glutCreateWindow("XtreemNodes Engine - By MCL Software and Cube Software");
|
playerRotY += 1.8;
|
||||||
|
}
|
||||||
glClearColor(.2, .7, .8 , 255);
|
|
||||||
glEnable(GL_DEPTH_TEST);
|
if(sf::Keyboard::isKeyPressed(sf::Keyboard::F1))
|
||||||
|
{
|
||||||
|
levelGen.setSeed();
|
||||||
// Load textures
|
levelGen.generateBlock();
|
||||||
textureHandler.loadAllTextures();
|
}
|
||||||
|
|
||||||
|
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
|
||||||
|
{
|
||||||
|
playerRotX += 1.8;
|
||||||
for(int x = 0; x < 16; x++)
|
}
|
||||||
{
|
|
||||||
for(int z = 0; z < 16; z++)
|
else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
|
||||||
{
|
{
|
||||||
for(int y = 0; y < 256; y++)
|
playerRotX = 1.8;
|
||||||
{
|
}
|
||||||
nodeManager.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));
|
// Mouse-based movement
|
||||||
}
|
sf::Vector2i mousePos = sf::Mouse::getPosition();
|
||||||
}
|
sf::Vector2i mousePosDiff = oldMousePos - mousePos;
|
||||||
}
|
playerRotX -= mousePosDiff.y;
|
||||||
|
playerRotY -= mousePosDiff.x;
|
||||||
for(int x = 0; x < 16; x++)
|
oldMousePos = sf::Vector2i(1920 / 2, 1080 / 2);
|
||||||
{
|
sf::Mouse::setPosition(sf::Vector2i(1920 / 2, 1080 / 2));
|
||||||
for(int z = 0; z < 16; z++)
|
|
||||||
{
|
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
|
||||||
for(int y = 0; y < 256; y++)
|
{
|
||||||
{
|
printf("PlayerX: %f, PlayerZ: %f", playerX, playerZ);
|
||||||
nodeManager1.addNode(rand() % 3, 0, x, y, z);
|
exit(0);
|
||||||
//printf("\nGet node at: %i\n Is air: %i", nodeManager.getNodeAt(x, y + 1, z) == 0, nodeManager.isAir(x, y + 1, z));
|
}
|
||||||
}
|
|
||||||
}
|
glutPostRedisplay();
|
||||||
}
|
glutTimerFunc(30, &updateTimer, 0);
|
||||||
|
}
|
||||||
|
|
||||||
glutDisplayFunc(&display);
|
int main(int argc, char **argv)
|
||||||
glutReshapeFunc(&reshape);
|
{
|
||||||
glutKeyboardFunc(&KeyboardFunc);
|
glutInit(&argc, argv);
|
||||||
|
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
|
||||||
glutMainLoop();
|
glutInitWindowSize(1920, 1080);
|
||||||
|
glutCreateWindow("XtreemNodes Engine - by MCL Software");
|
||||||
return 0;
|
|
||||||
}
|
glClearColor(.4, .7, .8 , 255);
|
||||||
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
glEnable(GL_TEXTURE_2D);
|
||||||
|
//glEnable(GL_CULL_FACE);
|
||||||
|
//glCullFace(GL_FRONT);
|
||||||
|
//glFrontFace(GL_CCW);
|
||||||
|
|
||||||
|
// Load textures
|
||||||
|
textureHandler.loadAllTextures();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
for(int y = 0; y < 16; y++)
|
||||||
|
{
|
||||||
|
for(int x = 0; x < 16; x++)
|
||||||
|
{
|
||||||
|
for(int z = 0; z < 16; z++)
|
||||||
|
{
|
||||||
|
Position2D block = BlockUtilities::getBlockFromNodeCoordinates(x, z);
|
||||||
|
printf("\n|x: %i |y: %i | z: %i | id: %i", x, y, z, blockManager.getNodeAt(x, y, z));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
levelGen.generateBlock();
|
||||||
|
|
||||||
|
updateTimer(0);
|
||||||
|
glutDisplayFunc(&display);
|
||||||
|
glutReshapeFunc(&reshape);
|
||||||
|
|
||||||
|
glutMainLoop();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|||||||