#include #include #include "Utilities.h" #include "MapBlock.h" #include "Base.h" #include "NodeRenderer.h" #include "TextureHandler.h" #include #include #include "FastNoiseLite.h" #include #include NodeRenderer renderer; //BlockManager blockManager; BlockManager blockManager; TextureHandler textureHandler; GLfloat playerX = 0; GLfloat playerY = -30; GLfloat playerZ = -100; GLfloat playerRotX = 0; GLfloat playerRotY = 0; void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glRotatef(playerRotX, 1.0F, .0F, .0F); glRotatef(playerRotY, .0F, 1.0F, .0F); glTranslatef(playerX, playerY, playerZ); //glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glBegin(GL_QUADS); for(int x = 0; x < 64; x++) { for(int y = 0; y < 64; y++) { for(int z = 0; z < 64; z++) { if(blockManager.getNodeAt(x, y, z) > 0) { textureHandler.getTextureForNode(x, y, z); renderer.renderNode(x, y, z); } } } } glEnd(); glFlush(); glutSwapBuffers(); /* sf::Vector2i lastMousePos = sf::Vector2i(0, 0); const sf::Window& window = nullptr; sf::Vector2i mouseDelta = sf::Mouse::getPosition(window) - lastMousePos; lastMousePos = sf::Mouse::getPosition(window);*/ //glutPostRedisplay(); } void reshape(int width, int height) { glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(30, width / (float) height, 5, 512.0F); glViewport(0, 0, width, height); glMatrixMode(GL_MODELVIEW); glutPostRedisplay(); } void updateTimer(int time) { // Movement if(sf::Keyboard::isKeyPressed(sf::Keyboard::W)) { playerZ += .8; } else if(sf::Keyboard::isKeyPressed(sf::Keyboard::S)) { playerZ -= .8; } if(sf::Keyboard::isKeyPressed(sf::Keyboard::A)) { playerX += .8; } else if(sf::Keyboard::isKeyPressed(sf::Keyboard::D)) { playerX -= .8; } // Rotation if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) { playerRotY -= .8; } else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) { playerRotY += .8; } if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) { playerRotX -= .8; } else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) { playerRotX += .8; } if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)) { exit(0); } glutPostRedisplay(); glutTimerFunc(30, &updateTimer, 0); } int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); glutInitWindowSize(800, 600); glutCreateWindow("XtreemNodes Engine - By MCL Software and Cube Software"); 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(); FastNoiseLite perlin, os, cellular; int seed = 138; 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); for(int bx = 0; bx < 4; bx++) { for(int bz = 0; bz < 4; bz++) { for(int x = 0; x < 16; x++) { for(int z = 0; z < 16; z++) { float cX = (float)x + (16 * bx); float cZ = (float)z + (16 * bz); for(int y = 0; y < 48 * abs(perlin.GetNoise(cX, cZ)) + (cellular.GetNoise(cX, cZ)) + 3; y++) { blockManager.mapBlocks[bx][bz].addNode(y > 30 ? 1 : 2, 0, x, y, z); } } } } } /* 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)); } } } */ updateTimer(0); glutDisplayFunc(&display); glutReshapeFunc(&reshape); glutMainLoop(); return 0; }