XtreemNodes/main.cpp

209 lines
4.0 KiB
C++
Raw Normal View History

2022-10-22 17:03:43 +02:00
#include <stdlib.h>
#include <GL/glut.h>
2022-10-23 23:44:58 +02:00
#include "MapBlock.h"
#include "Base.h"
2022-10-22 17:03:43 +02:00
#include "NodeRenderer.h"
2022-10-23 23:44:58 +02:00
#include "TextureHandler.h"
2022-10-22 17:03:43 +02:00
#include <cstdio>
#include <random>
2022-10-29 05:47:09 +02:00
#include <SFML/System.hpp>
2022-10-29 05:55:27 +02:00
#include <SFML/Window.hpp>
2022-10-22 17:03:43 +02:00
NodeRenderer renderer;
//BlockManager blockManager;
2022-10-29 05:47:09 +02:00
NodeManager nodeManager;
NodeManager nodeManager1;
BlockManager blockManager;
2022-10-23 23:44:58 +02:00
TextureHandler textureHandler;
2022-10-22 17:03:43 +02:00
GLfloat playerX = 0;
GLfloat playerY = -30;
GLfloat playerZ = -100;
GLfloat playerRotX = 0;
2022-10-23 23:44:58 +02:00
void display()
2022-10-22 17:03:43 +02:00
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(playerX, playerY, playerZ);
glRotatef(playerRotX, .0F, 1.0F, .0F);
2022-10-23 23:44:58 +02:00
glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
2022-10-22 17:03:43 +02:00
glBegin(GL_QUADS);
for(int x = 0; x < 16; x++)
{
for(int z = 0; z < 16; z++)
{
for(int y = 0; y < 256; y++)
{
2022-10-23 23:44:58 +02:00
if(nodeManager.getNodeAt(x, y, z) > 0)
{
textureHandler.getTextureForNode(x, y, z);
2022-10-22 17:03:43 +02:00
renderer.renderNode(x, y, z);
2022-10-23 23:44:58 +02:00
}
2022-10-22 17:03:43 +02:00
}
}
}
2022-10-23 23:44:58 +02:00
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);
}
}
}
}
2022-10-22 17:03:43 +02:00
glEnd();
glFlush();
glutSwapBuffers();
2022-10-29 05:55:27 +02:00
sf::Vector2i lastMousePos = sf::Vector2i(0, 0);
sf::Vector2i mouseDelta = sf::Mouse::getPosition() - lastMousePos;
lastMousePos = sf::Mouse::getPosition();
2022-10-22 17:03:43 +02:00
glutPostRedisplay();
}
2022-10-23 23:44:58 +02:00
void reshape(int width, int height)
2022-10-22 17:03:43 +02:00
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(20, width / (float) height, 5, 150);
glViewport(0, 0, width, height);
glMatrixMode(GL_MODELVIEW);
glutPostRedisplay();
}
2022-10-29 05:47:09 +02:00
void updateTimer()
{
//glutTimerFunc(30, &updateTimer, 0);
}
2022-10-22 17:03:43 +02:00
void KeyboardFunc(unsigned char key, int x, int y)
{
if(key == 'a')
{
playerX += .8F;
}
if(key == 'd')
{
playerX -= .8F;
}
if(key == 'w')
{
playerZ += .8F;
}
if(key == 's')
{
playerZ -= .8F;
}
if(key == 'q')
{
playerY += .1F;
}
if(key == 'e')
{
playerY -= .1F;
}
if(key == 'f')
{
playerRotX -= .8F;
}
if(key == 'h')
{
playerRotX += .8F;
}
2022-10-23 23:44:58 +02:00
2022-10-22 17:03:43 +02:00
if(key == 27)
{
exit(0);
}
}
2022-10-23 23:44:58 +02:00
2022-10-29 05:47:09 +02:00
2022-10-22 17:03:43 +02:00
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");
2022-10-22 17:03:43 +02:00
2022-10-23 23:44:58 +02:00
glClearColor(.2, .7, .8 , 255);
2022-10-22 17:03:43 +02:00
glEnable(GL_DEPTH_TEST);
2022-10-23 23:44:58 +02:00
// Load textures
textureHandler.loadAllTextures();
2022-10-22 17:03:43 +02:00
2022-10-23 23:44:58 +02:00
for(int x = 0; x < 16; x++)
{
for(int z = 0; z < 16; z++)
{
for(int y = 0; y < 256; y++)
{
2022-10-29 05:47:09 +02:00
blockManager.mapBlocks[0][0].addNode(rand() % 3, 0, x, y, z);
2022-10-23 23:44:58 +02:00
//printf("\nGet node at: %i\n Is air: %i", nodeManager.getNodeAt(x, y + 1, z) == 0, nodeManager.isAir(x, y + 1, z));
}
}
}
2022-10-22 17:03:43 +02:00
for(int x = 0; x < 16; x++)
{
for(int z = 0; z < 16; z++)
{
for(int y = 0; y < 256; y++)
{
2022-10-29 05:47:09 +02:00
blockManager.mapBlocks[1][0].addNode(rand() % 3, 0, x, y, z);
2022-10-22 17:03:43 +02:00
//printf("\nGet node at: %i\n Is air: %i", nodeManager.getNodeAt(x, y + 1, z) == 0, nodeManager.isAir(x, y + 1, z));
}
}
}
2022-10-29 05:47:09 +02:00
updateTimer();
2022-10-23 23:44:58 +02:00
glutDisplayFunc(&display);
glutReshapeFunc(&reshape);
2022-10-22 17:03:43 +02:00
glutKeyboardFunc(&KeyboardFunc);
glutMainLoop();
return 0;
}