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