Przeglądaj źródła

Delete minecrown sample

Daniele Bartolini 13 lat temu
rodzic
commit
5d34666b71

+ 0 - 885
samples/minecrown/WorldTerrain.cpp

@@ -1,885 +0,0 @@
-#include "WorldTerrain.h"
-#include <time.h>
-#include <cstdlib>
-#include "Crown.h"
-#include "perlin.h"
-#include <iostream>
-
-using namespace Crown;
-
-int perlinSeed;
-extern MovableCamera* cam;
-
-void DrawWiredCube(float x, float y, float z, float size);
-
-WorldTerrain::WorldTerrain()
-{
-	Clear();
-
-	mChunkX = 0;
-	mChunkZ = 0;
-	mChunkH = 0;
-
-	mDrawGrid = true;
-	
-	
-	
-	mPlayerChunkX = (CHUNKS_COUNT+1)/2.0f;
-	mPlayerChunkZ = (CHUNKS_COUNT+1)/2.0f;
-	mPlayerChunkH = CHUNKS_COUNT_H;
-	mPlayerPosition = Vec3((mPlayerChunkX + 0.5) * CHUNK_SIZE, mPlayerChunkH * CHUNK_SIZE, (mPlayerChunkZ + 0.5) * CHUNK_SIZE);
-
-	for(int x = 0; x < CHUNKS_COUNT; x++)
-	{
-		for(int z = 0; z < CHUNKS_COUNT; z++)
-		{
-			for(int h = 0; h < CHUNKS_COUNT_H; h++)
-			{
-					mChunks[x][z][h] = new Chunk(this);
-			}
-		}
-	}
-
-	BMPImageLoader bmp;
-	Image* image = bmp.LoadFile("res/terrain.bmp");
-	mTerrainTexture = new GLTexture();
-	//mTerrainTexture->SetWrap(TW_CLAMP_TO_EDGE);
-	mTerrainTexture->SetGenerateMipMaps(true);
-	mTerrainTexture->SetFilter(TF_ANISOTROPIC);
-	mTerrainTexture->CreateFromImage(image);
-
-	delete image;
-
-	GLfloat fogColor[4] = {0.457f, 0.754f, 1.0f, 1.0f};//{0.5, 0.5, 0.5, 1.0}; 
-
-	glEnable (GL_FOG);
-	glFogi (GL_FOG_MODE, GL_LINEAR);
-	glFogf(GL_FOG_START, 0.0f);
-	glFogf(GL_FOG_END, 10.0f);
-	glFogfv (GL_FOG_COLOR, fogColor);
-	glHint (GL_FOG_HINT, GL_NICEST);
-
-	glFogi(GL_FOG_DISTANCE_MODE_NV, GL_EYE_RADIAL_NV);
-
-	mViewDistance = 128;
-	CycleViewDistance();
-}
-
-WorldTerrain::~WorldTerrain()
-{
-	for(int x = 0; x < CHUNKS_COUNT; x++)
-	{
-		for(int z = 0; z < CHUNKS_COUNT; z++)
-		{
-			for(int h = 0; h < CHUNKS_COUNT_H; h++)
-			{
-
-					delete mChunks[x][z][h];
-			}
-		}
-	}
-
-	delete mTerrainTexture;
-}
-
-void WorldTerrain::Clear()
-{
-	for(int x = 0; x < WORLD_SIZE; x++)
-	{
-		for(int z = 0; z < WORLD_SIZE; z++)
-		{
-			for(int h = 0; h < WORLD_SIZE_H; h++)
-			{
-				mBlocks[x][z][h].opaque = false;
-				mBlocks[x][z][h].faceVisibility = FV_NONE;
-				mBlocks[x][z][h].light = 4;
-			}
-		}
-	}
-}
-
-void WorldTerrain::RandomMap(int groundLevel, int seed, int octaves, int freq)
-{
-	Clear();
-
-	Perlin per(octaves, freq, WORLD_SIZE_H/2, seed);
-
-	for(int x = 0; x < WORLD_SIZE; x++)
-	{
-		for(int z = 0; z < WORLD_SIZE; z++)
-		{
-			int height = per.Get(x * 1.0f / WORLD_SIZE, z * 1.0f / WORLD_SIZE) - groundLevel;
-			if (height < 0)
-				height /= 6;
-			height = (WORLD_SIZE_H / 2) + height;
-			for(int h = 0; h < height; h++)
-				mBlocks[x][z][h].opaque = true;
-		}
-	}
-
-	int px = (int) (cam->GetPosition().x / CubeSize);
-	int pz = (int) (cam->GetPosition().z / CubeSize);
-	int ph = WORLD_SIZE_H-1;
-
-	while(ph > 1 && !mBlocks[px][pz][ph-1].opaque)
-		ph--;
-
-	ph++;
-
-	mPlayerChunkX = px / CHUNK_SIZE;
-	mPlayerChunkZ = pz / CHUNK_SIZE;
-	mPlayerChunkH = ph / CHUNK_SIZE;
-
-	cam->SetPosition(Vec3(px*CubeSize, ph*CubeSize, pz*CubeSize));
-
-
-	RecalculateVisibleBlocksSides();
-	RecalculateSunlight();
-
-	RegenerateTerrain();
-}
-
-void WorldTerrain::UpdateVisibleNeighbourBlocks(Crown::uint xC, Crown::uint zC, Crown::uint hC)
-{
-	for(int x = xC-1; x < (int)xC+2; x++)
-	{
-		if (x < 0 || x >= WORLD_SIZE)
-			continue;
-		for(int z = zC-1; z < (int)zC+2; z++)
-		{
-			if (z < 0 || z >= WORLD_SIZE)
-				continue;
-			for(int h = hC-1; h < (int)hC+2; h++)
-			{
-				if (h<0 || h>=WORLD_SIZE_H)
-					continue;
-				Block& b = mBlocks[x][z][h];
-				b.faceVisibility = FV_NONE;
-				if (b.opaque)
-				{
-					if (x == 0 || !mBlocks[x-1][z][h].opaque)
-						b.faceVisibility |= FV_LEFT;
-				
-					if (z == 0 || !mBlocks[x][z-1][h].opaque)
-						b.faceVisibility |= FV_BACK;
-
-					if (h == 0 || !mBlocks[x][z][h-1].opaque)
-						b.faceVisibility |= FV_BOTTOM;
-
-					if (x == WORLD_SIZE-1 || !mBlocks[x+1][z][h].opaque)
-						b.faceVisibility |= FV_RIGHT;
-
-					if (z == WORLD_SIZE-1 || !mBlocks[x][z+1][h].opaque)
-						b.faceVisibility |= FV_FRONT;
-
-					if (h == WORLD_SIZE_H-1 || !mBlocks[x][z][h+1].opaque)
-						b.faceVisibility |= FV_TOP;
-				}
-
-				Crown::uint cx = x / CHUNK_SIZE;
-				Crown::uint cz = z / CHUNK_SIZE;
-				Crown::uint ch = h / CHUNK_SIZE;
-
-				if (cx < 0 || cz < 0 || ch < 0 || cx >= CHUNKS_COUNT || cz >= CHUNKS_COUNT || ch >= CHUNKS_COUNT_H)
-					continue;
-
-				if (b.faceVisibility == FV_NONE)
-					mChunks[cx][cz][ch]->BlockRemoved(x, z, h);
-				else
-					mChunks[cx][cz][ch]->BlockRevealed(x, z, h);
-			}
-		}
-	}
-}
-
-void WorldTerrain::RecalculateVisibleBlocksSides()
-{
-	for(int x = 0; x < WORLD_SIZE; x++)
-	{
-		for(int z = 0; z < WORLD_SIZE; z++)
-		{
-			for(int h = 0; h < WORLD_SIZE_H; h++)
-			{
-				Block& b = mBlocks[x][z][h];
-				Crown::uint fv = FV_NONE;
-				if (b.opaque)
-				{
-					if (x == 0 || !mBlocks[x-1][z][h].opaque)
-						fv |= FV_LEFT;
-					if (x == WORLD_SIZE-1 || !mBlocks[x+1][z][h].opaque)
-						fv |= FV_RIGHT;
-				
-					if (z == 0 || !mBlocks[x][z-1][h].opaque)
-						fv |= FV_BACK;
-					if (z == WORLD_SIZE-1 || !mBlocks[x][z+1][h].opaque)
-						fv |= FV_FRONT;
-
-					if (h == 0 || !mBlocks[x][z][h-1].opaque)
-						fv |= FV_BOTTOM;
-					if (h == WORLD_SIZE_H-1 || !mBlocks[x][z][h+1].opaque)
-						fv |= FV_TOP;
-				}
-				b.faceVisibility = fv;
-			}
-		}
-	}
-}
-
-void WorldTerrain::RecalculateSunlight()
-{
-	for(int x = 0; x < WORLD_SIZE; x++)
-	{
-		for(int z = 0; z < WORLD_SIZE; z++)
-		{
-			mBlocks[x][z][WORLD_SIZE_H-1].light = 15;
-		}
-	}
-
-	for(int x = 0; x < WORLD_SIZE; x++)
-	{
-		for(int z = 0; z < WORLD_SIZE; z++)
-		{
-			for(int h = WORLD_SIZE_H-2; h > 0 && !mBlocks[x][z][h].opaque; h--)
-			{
-				mBlocks[x][z][h].light = 15;
-			}
-		}
-	}
-}
-
-void WorldTerrain::RegenerateTerrain()
-{
-
-	for(int x = 0; x < CHUNKS_COUNT; x++)
-	{
-		for(int z = 0; z < CHUNKS_COUNT; z++)
-		{
-			for(int h = 0; h < CHUNKS_COUNT_H; h++)
-			{
-					mChunks[x][z][h]->AssignLocation(x*CHUNK_SIZE	, z*CHUNK_SIZE, h*CHUNK_SIZE);
-			}
-		}
-	}
-}
-
-void WorldTerrain::Render()
-{
-	glEnable(GL_TEXTURE_2D);
-	Renderer* r = GetDevice()->GetRenderer();
-	r->SetTexture(1, mTerrainTexture);
-	//mTerrainTexture->MakeCurrent();
-
-	glEnableClientState(GL_VERTEX_ARRAY);
-	glEnableClientState(GL_NORMAL_ARRAY);
-	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
-	glEnableClientState(GL_COLOR_ARRAY);
-	
-	mChunkRegenerationSlots = 30;
-
-	for(int x = 0; x < CHUNKS_COUNT; x++)
-	{
-		for(int z = 0; z < CHUNKS_COUNT; z++)
-		{
-			for(int h = 0; h < CHUNKS_COUNT_H; h++)
-			{
-					mChunks[x][z][h]->Render();
-			}
-		}
-	}
-
-	
-	glDisableClientState(GL_VERTEX_ARRAY);
-	glDisableClientState(GL_NORMAL_ARRAY);
-	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
-	glDisableClientState(GL_COLOR_ARRAY);
-
-	glDisable(GL_TEXTURE_2D);
-}
-
-void WorldTerrain::SetPlayerPosition(Vec3 newPosition)
-{
-	newPosition /= CubeSize;
-	Crown::uint chunkX = (Crown::uint) (newPosition.x / (CHUNK_SIZE)) - mChunkX;
-	Crown::uint chunkZ = (Crown::uint) (newPosition.z / (CHUNK_SIZE)) - mChunkZ;
-	Crown::uint chunkH = (Crown::uint) (newPosition.y / (CHUNK_SIZE)) - mChunkH;
-
-	mPlayerPosition = newPosition;
-
-	if (chunkX > (CHUNKS_COUNT+1)/2  && (mChunkX + CHUNKS_COUNT) * CHUNK_SIZE < WORLD_SIZE)
-	{
-		//Fai uno spostamento verso x+
-		Chunk* tempChunks[CHUNKS_COUNT][CHUNKS_COUNT_H];
-
-		mChunkX += 1;
-
-		ExtractChunksFromX(tempChunks, 0);
-
-		//Slide all chunks behind in the -x direction
-		for(int x = 0; x < CHUNKS_COUNT-1; x++)
-		{
-			for(int z = 0; z < CHUNKS_COUNT; z++)
-			{
-				for(int h = 0; h < CHUNKS_COUNT_H; h++)
-				{
-						Chunk* c = mChunks[x+1][z][h];
-						mChunks[x][z][h] = c;
-						c->mRelX--;
-						c->UpdateShouldRender();
-				}
-			}
-		}
-
-		ReplaceChunksInX(tempChunks, CHUNKS_COUNT-1);
-	}
-	else if (chunkX < (CHUNKS_COUNT+1)/2  && mChunkX > 0)
-	{
-		//Fai uno spostamento verso x-
-		Chunk* tempChunks[CHUNKS_COUNT][CHUNKS_COUNT_H];
-
-		mChunkX -= 1;
-
-		ExtractChunksFromX(tempChunks, CHUNKS_COUNT-1);
-
-		for(int x = CHUNKS_COUNT-1; x > 0; x--)
-		{
-			for(int z = 0; z < CHUNKS_COUNT; z++)
-			{
-				for(int h = 0; h < CHUNKS_COUNT_H; h++)
-				{
-						Chunk* c = mChunks[x-1][z][h];
-						mChunks[x][z][h] = c;
-						c->mRelX++;
-						c->UpdateShouldRender();
-				}
-			}
-		}
-
-		ReplaceChunksInX(tempChunks, 0);
-	}
-	else if (chunkZ > (CHUNKS_COUNT+1)/2  && (mChunkZ + CHUNKS_COUNT) * CHUNK_SIZE < WORLD_SIZE)
-	{
-		//Fai uno spostamento verso z+
-		Chunk* tempChunks[CHUNKS_COUNT][CHUNKS_COUNT_H];
-
-		mChunkZ += 1;
-
-		ExtractChunksFromZ(tempChunks, 0);
-
-		for(int z = 0; z < CHUNKS_COUNT-1; z++)
-		{
-			for(int x = 0; x < CHUNKS_COUNT; x++)
-			{
-				for(int h = 0; h < CHUNKS_COUNT_H; h++)
-				{
-						Chunk* c = mChunks[x][z+1][h];
-						mChunks[x][z][h] = c;
-						c->mRelZ--;
-						c->UpdateShouldRender();
-				}
-			}
-		}
-
-		ReplaceChunksInZ(tempChunks, CHUNKS_COUNT-1);	
-	}
-	else if (chunkZ < (CHUNKS_COUNT+1)/2  && mChunkZ > 0)
-	{
-		//Fai uno spostamento verso z-
-		Chunk* tempChunks[CHUNKS_COUNT][CHUNKS_COUNT_H];
-
-		mChunkZ -= 1;
-
-		ExtractChunksFromZ(tempChunks, CHUNKS_COUNT-1);
-
-		for(int z = CHUNKS_COUNT-1; z > 0; z--)
-		{
-			for(int x = 0; x < CHUNKS_COUNT; x++)
-			{
-				for(int h = 0; h < CHUNKS_COUNT_H; h++)
-				{
-						Chunk* c = mChunks[x][z-1][h];
-						mChunks[x][z][h] = c;
-						c->mRelZ++;
-						c->UpdateShouldRender();
-				}
-			}
-		}
-
-		ReplaceChunksInZ(tempChunks, 0);
-	}
-	else if (chunkX != mPlayerChunkX || chunkZ != mPlayerChunkZ || chunkH != mPlayerChunkH)
-	{
-		if (chunkX >= CHUNKS_COUNT || chunkZ >= CHUNKS_COUNT || chunkH >= CHUNKS_COUNT_H)
-			return;
-		Crown::uint xOff = chunkX - mPlayerChunkX;
-		Crown::uint zOff = chunkZ - mPlayerChunkZ;
-		Crown::uint hOff = chunkH - mPlayerChunkH;
-		mPlayerChunkX = chunkX;
-		mPlayerChunkZ = chunkZ;
-		mPlayerChunkH = chunkH;
-		//Just update the ShouldDraw of chunks
-
-		for(int x = 0; x < CHUNKS_COUNT; x++)
-		{
-			for(int z = 0; z < CHUNKS_COUNT; z++)
-			{
-				for(int h = 0; h < CHUNKS_COUNT_H; h++)
-				{
-						mChunks[x][z][h]->UpdateShouldRender();
-						mChunks[x][z][h]->mRelX -= xOff;
-						mChunks[x][z][h]->mRelZ -= zOff;
-						mChunks[x][z][h]->mRelH -= hOff;
-				}
-			}
-		}
-	}
-}
-
-void WorldTerrain::LOL()
-{
-	Crown::uint x = rand() % CHUNK_SIZE;
-	Crown::uint z = rand() % CHUNK_SIZE;
-
-	Crown::uint h = 0;
-	while (h < WORLD_SIZE_H-1 && mBlocks[x][z][h+1].opaque)
-		h++;
-
-	mBlocks[x][z][h].opaque = false;
-	
-	UpdateVisibleNeighbourBlocks(x, z, h);
-}
-
-void WorldTerrain::CycleViewDistance()
-{
-	if (mViewDistance == 256)
-		mViewDistance = 32;
-	else
-		mViewDistance <<= 1;
-
-	std::cout << "View distance changed: " << mViewDistance << std::endl;
-	
-	cam->SetFarClipDistance(mViewDistance);
-	glFogf(GL_FOG_START, mViewDistance*CubeSize*0.35);
-	glFogf(GL_FOG_END, mViewDistance*CubeSize);
-}
-
-void WorldTerrain::ExtractChunksFromX(Chunk* destChunks[CHUNKS_COUNT][CHUNKS_COUNT_H], Crown::uint x)
-{
-	for(int z = 0; z < CHUNKS_COUNT; z++)
-	{
-		for(int h = 0; h < CHUNKS_COUNT_H; h++)
-		{
-				destChunks[z][h] = mChunks[x][z][h];
-		}
-	}
-}
-
-void WorldTerrain::ReplaceChunksInX(Chunk* srcChunks[CHUNKS_COUNT][CHUNKS_COUNT_H], Crown::uint x)
-{
-	for(int z = 0; z < CHUNKS_COUNT; z++)
-	{
-		for(int h = 0; h < CHUNKS_COUNT_H; h++)
-		{
-				Chunk* c;
-				c = srcChunks[z][h];
-				mChunks[x][z][h] = c;
-				c->AssignLocation((mChunkX + x) * CHUNK_SIZE, c->mZ, c->mH);
-		}
-	}
-}
-
-void WorldTerrain::ExtractChunksFromZ(Chunk* destChunks[CHUNKS_COUNT][CHUNKS_COUNT_H], Crown::uint z)
-{
-	for(int x = 0; x < CHUNKS_COUNT; x++)
-	{
-		for(int h = 0; h < CHUNKS_COUNT_H; h++)
-		{
-				destChunks[x][h] = mChunks[x][z][h];
-		}
-	}
-}
-
-void WorldTerrain::ReplaceChunksInZ(Chunk* srcChunks[CHUNKS_COUNT][CHUNKS_COUNT_H], Crown::uint z)
-{
-	for(int x = 0; x < CHUNKS_COUNT; x++)
-	{
-		for(int h = 0; h < CHUNKS_COUNT_H; h++)
-		{
-				Chunk* c;
-				c = srcChunks[x][h];
-				mChunks[x][z][h] = c;
-				c->AssignLocation(c->mX, (mChunkZ + z) * CHUNK_SIZE, c->mH);
-		}
-	}
-}
-
-//------------CHUNK-------------
-Chunk::Chunk(WorldTerrain* terrain):
-	mWorldTerrain(terrain), mX(0), mZ(0), mH(0), mRelX(0), mRelZ(0), mRelH(0), mIsDirty(false), mShouldRender(false),
-	mCandidateBlocks(0),
-	mVertexBuffer(NULL), mIndexBuffer(NULL),
-	mVertex(NULL), mVertexCount(0)
-{
-	for(int i = 0; i < 6; i++)
-	{
-		mIndices[i] = NULL;
-		mIndicesCount[i] = 0;
-	}
-
-	mVertexBuffer = GetDevice()->GetRenderer()->CreateVertexBuffer();
-	mIndexBuffer = GetDevice()->GetRenderer()->CreateIndexBuffer();
-}
-
-Chunk::~Chunk()
-{
-	delete[] mVertex;
-	for(int i = 0; i < 6; i++)
-		if (mIndices[i] != NULL)
-		{
-			delete[] mIndices[i];
-			mIndices[i] = NULL;
-		}
-}
-
-void Chunk::Render()
-{
-	Box box;
-	box.min = Vec3(mX*CubeSize, mH*CubeSize, mZ*CubeSize);
-	box.max = Vec3((mX+CHUNK_SIZE)*CubeSize, (mH+CHUNK_SIZE)*CubeSize, (mZ+CHUNK_SIZE)*CubeSize);
-
-	//Vec3 minToMax = box.max - box.min;
-	//Compensate imprecise frustum culling
-	//box.min -= minToMax/(18*1.6);
-	//box.max += minToMax/(18*1.6);
-
-	if (mShouldRender)// && cam->GetFrustum().IntersectsBox(box))
-	{
-		if (mWorldTerrain->mDrawGrid)
-		{
-			glColor3f(0.6f, 0.6f, 1.0f);
-			DrawWiredCube(mX*CubeSize, mH*CubeSize, mZ*CubeSize, 16*CubeSize);
-			glColor3f(1.0f, 1.0f, 1.0f);
-		}
-
-		if (mCandidateBlocks > 0)
-		{
-
-			if (mIsDirty && mWorldTerrain->mChunkRegenerationSlots > 0)
-			{
-				mWorldTerrain->mChunkRegenerationSlots--;
-				mIsDirty = false;
-				mWorldTerrain->RegeneratedChunks++;
-				RegenerateChunk();
-			}
-
-			if (mVertexBuffer == NULL || mIndexBuffer == NULL)
-				return;
-
-			mVertexBuffer->MakeCurrent();
-			mIndexBuffer->MakeCurrent();
-		
-			if (mRelX >= 0)
-				glDrawElements(GL_TRIANGLES, mIndicesCount[FB_LEFT], GL_UNSIGNED_INT, (void*) (mIndicesOffsets[FB_LEFT]*sizeof(Crown::uint)));
-			if (mRelX <= 0)
-				glDrawElements(GL_TRIANGLES, mIndicesCount[FB_RIGHT], GL_UNSIGNED_INT, (void*) (mIndicesOffsets[FB_RIGHT]*sizeof(Crown::uint)));
-
-			if (mRelZ >= 0)
-				glDrawElements(GL_TRIANGLES, mIndicesCount[FB_BACK], GL_UNSIGNED_INT, (void*) (mIndicesOffsets[FB_BACK]*sizeof(Crown::uint)));
-			if (mRelZ <= 0)
-				glDrawElements(GL_TRIANGLES, mIndicesCount[FB_FRONT], GL_UNSIGNED_INT, (void*) (mIndicesOffsets[FB_FRONT]*sizeof(Crown::uint)));
-
-			if (mRelH >= 0)
-				glDrawElements(GL_TRIANGLES, mIndicesCount[FB_BOTTOM], GL_UNSIGNED_INT, (void*) (mIndicesOffsets[FB_BOTTOM]*sizeof(Crown::uint)));
-			if (mRelH <= 0)
-				glDrawElements(GL_TRIANGLES, mIndicesCount[FB_TOP], GL_UNSIGNED_INT, (void*) (mIndicesOffsets[FB_TOP]*sizeof(Crown::uint)));
-		}
-	}
-
-	if (mVertex)
-	{
-		delete[] mVertex;
-		mVertex = NULL;
-		for(int i = 0; i < 6; i++)
-		{
-			if (mIndices[i] != NULL)
-			{
-				delete[] mIndices[i];
-				mIndices[i] = NULL;
-			}
-		}
-	}
-}
-
-void Chunk::UpdateShouldRender()
-{
-	float d = (float) (pow(mRelX*CHUNK_SIZE + CHUNK_SIZE / (mRelX < 0 ? -2.0 : 2.0), 2) +
-										 pow(mRelZ*CHUNK_SIZE + CHUNK_SIZE / (mRelZ < 0 ? -2.0 : 2.0), 2));
-
-	if (d > pow((float)mWorldTerrain->mViewDistance + 2*CHUNK_SIZE, 2))
-		mShouldRender = false;
-	else
-		mShouldRender = true;
-}
-
-void Chunk::Dirty()
-{
-	mIsDirty = true;
-}
-
-void Chunk::AssignLocation(Crown::uint x, Crown::uint z, Crown::uint h)
-{
-	mX = x;
-	mZ = z;
-	mH = h;
-
-	int xTo = mX + CHUNK_SIZE;
-	int zTo = mZ + CHUNK_SIZE;
-	int hTo = mH + CHUNK_SIZE;
-
-	mCandidateBlocks = 0;
-
-	mBlocksToRender.Clear();
-
-	for(int x = mX; x < xTo; x++)
-	{
-		for(int z = mZ; z < zTo; z++)
-		{
-			for(int h = mH; h < hTo; h++)
-			{
-				Block& b = mWorldTerrain->mBlocks[x][z][h];
-				if (!b.opaque || b.faceVisibility == 0)
-					continue;
-
-				BlockToRender bt = {&b, x, z, h};
-				mBlocksToRender.Append(bt);
-				mCandidateBlocks++;
-			}
-		}
-	}
-
-	mRelX = mX / CHUNK_SIZE - (mWorldTerrain->mChunkX + mWorldTerrain->mPlayerChunkX);
-	mRelZ = mZ / CHUNK_SIZE - (mWorldTerrain->mChunkZ + mWorldTerrain->mPlayerChunkZ);
-	mRelH = mH / CHUNK_SIZE - (mWorldTerrain->mChunkH + mWorldTerrain->mPlayerChunkH);
-
-	mIsDirty = true;
-	UpdateShouldRender();
-}
-
-void Chunk::BlockRemoved(Crown::uint x, Crown::uint z, Crown::uint h)
-{
-	Block* block = &mWorldTerrain->mBlocks[x][z][h];
-	for(int i = 0; i<mBlocksToRender.GetSize(); i++)
-	{
-		if (mBlocksToRender[i].block == block)
-		{
-			mBlocksToRender[i] = mBlocksToRender[mBlocksToRender.GetSize()-1];
-			mBlocksToRender.Remove(mBlocksToRender.GetSize()-1);
-			mCandidateBlocks--;
-			mIsDirty = true;
-			return;
-		}
-	}
-}
-
-void Chunk::BlockRevealed(Crown::uint x, Crown::uint z, Crown::uint h)
-{
-	mIsDirty = true;
-	Block* block = &mWorldTerrain->mBlocks[x][z][h];
-	for(int i = 0; i<mBlocksToRender.GetSize(); i++)
-	{
-		if (mBlocksToRender[i].block == block)
-		{
-			return;
-		}
-	}
-	BlockToRender bt = {block, x, z, h};
-	mBlocksToRender.Append(bt);
-	mCandidateBlocks++;
-}
-
-void Chunk::RegenerateChunk()
-{
-	mVertexCount = 0;
-	for(int i = 0; i < 6; i++)
-		mIndicesCount[i] = 0;
-
-	if (mCandidateBlocks == 0)
-	{
-		mCandidateBlocks = 0;
-		mVertexBuffer->SetVertexData((VertexBufferMode) (VBM_NORMAL_COORDS | VBM_TEXTURE_COORDS | VBM_COLOR_COORDS), NULL, 0);
-		mIndexBuffer->SetIndexData(NULL, 0);
-		return;
-	}
-
-	if (mVertex != NULL)
-		delete[] mVertex;
-	for(int i = 0; i < 6; i++)
-		if (mIndices[i] != NULL)
-			delete[] mIndices[i];
-
-	mVertex = new VertexData[mCandidateBlocks * 24];
-	for(int i = 0; i < 6; i++)
-		mIndices[i] = new Crown::uint[mCandidateBlocks * 36];
-
-	for(int i = 0; i<mBlocksToRender.GetSize(); i++)
-	{
-		BlockToRender& bt = mBlocksToRender[i];
-		Block* b = bt.block;
-
-		uchar light;
-
-		if (b->faceVisibility & FV_TOP)
-		{
-			if (bt.h < WORLD_SIZE_H-1)
-				light = mWorldTerrain->mBlocks[bt.x][bt.z][bt.h+1].light;
-			AddFace(bt.x, bt.z, bt.h, FB_TOP, light);
-		}
-
-		if (b->faceVisibility & FV_BOTTOM)
-		{
-			if (bt.h > 0)
-				light = mWorldTerrain->mBlocks[bt.x][bt.z][bt.h-1].light;
-			AddFace(bt.x, bt.z, bt.h, FB_BOTTOM, light);
-		}
-
-		if (b->faceVisibility & FV_LEFT)
-		{
-			if (bt.x > 0)
-				light = mWorldTerrain->mBlocks[bt.x-1][bt.z][bt.h].light;
-			AddFace(bt.x, bt.z, bt.h, FB_LEFT, light);
-		}
-
-		if (b->faceVisibility & FV_RIGHT)
-		{
-			if (bt.x < WORLD_SIZE_H-1)
-				light = mWorldTerrain->mBlocks[bt.x+1][bt.z][bt.h].light;
-			AddFace(bt.x, bt.z, bt.h, FB_RIGHT, light);
-		}
-
-		if (b->faceVisibility & FV_FRONT)
-		{
-			if (bt.z < WORLD_SIZE_H-1)
-				light = mWorldTerrain->mBlocks[bt.x][bt.z+1][bt.h].light;
-			AddFace(bt.x, bt.z, bt.h, FB_FRONT, light);
-		}
-
-		if (b->faceVisibility & FV_BACK)
-		{
-			if (bt.z > 0)
-				light = mWorldTerrain->mBlocks[bt.x][bt.z-1][bt.h].light;
-			AddFace(bt.x, bt.z, bt.h, FB_BACK, light);
-		}
-	}
-
-	mVertexBuffer->SetVertexData((VertexBufferMode) (VBM_NORMAL_COORDS | VBM_TEXTURE_COORDS | VBM_COLOR_COORDS), (float*)mVertex, mVertexCount);
-	int totIndicesCount = 0;
-	for(int i = 0; i < 6; i++)
-		totIndicesCount += mIndicesCount[i];
-
-	mIndexBuffer->SetIndexData(NULL, totIndicesCount);
-	totIndicesCount = 0;
-	for(int i = 0; i < 6; i++)
-	{
-		mIndicesOffsets[i] = totIndicesCount;
-		if (mIndicesCount[i] > 0)
-		{
-			mIndexBuffer->SetIndexSubData(mIndices[i], totIndicesCount, mIndicesCount[i]);
-			totIndicesCount += mIndicesCount[i];
-		}
-	}
-}
-
-void Chunk::AddFace(int x, int z, int h, FaceBuffer face, uchar light)
-{
-	float xx = x * CubeSize;
-	float zz = z * CubeSize;
-	float hh = h * CubeSize;
-
-	FaceMaterial faceMaterial = GetMaterial(0, face);
-
-	float lightFactor = light / 15.0f;
-	AddFace(faceMaterial, Vec3(xx, hh, zz), lightFactor, mIndices[face], mIndicesCount[face]);
-}
-
-void Chunk::AddFace(const FaceMaterial& faceMaterial, Vec3 traslation, float lightFactor, Crown::uint* index, Crown::uint& indicesCount)
-{
-	Crown::uint firstIdx = mVertexCount;
-	
-	VertexData vd;
-	
-	vd = faceMaterial.vd0;
-	vd.position += traslation;
-	//vd.color *= lightFactor;
-	memcpy(&mVertex[mVertexCount], &vd, sizeof(VertexData));
-	mVertexCount++;
-	
-	vd = faceMaterial.vd1;
-	vd.position += traslation;
-	//vd.color *= lightFactor;
-	memcpy(&mVertex[mVertexCount], &vd, sizeof(VertexData));
-	mVertexCount++;
-	
-	vd = faceMaterial.vd2;
-	vd.position += traslation;
-	//vd.color *= lightFactor;
-	memcpy(&mVertex[mVertexCount], &vd, sizeof(VertexData));
-	mVertexCount++;
-	
-	vd = faceMaterial.vd3;
-	vd.position += traslation;
-	//vd.color *= lightFactor;
-	memcpy(&mVertex[mVertexCount], &vd, sizeof(VertexData));
-	mVertexCount++;
-	
-	index[indicesCount++] = firstIdx;
-	index[indicesCount++] = firstIdx+1;
-	index[indicesCount++] = firstIdx+2;
-
-	index[indicesCount++] = firstIdx;
-	index[indicesCount++] = firstIdx+2;
-	index[indicesCount++] = firstIdx+3;
-}
-
-
-void DrawWiredCube(float x, float y, float z, float size)
-{
-	glBegin(GL_LINES);
-
-	glVertex3f(x, y, z);
-	glVertex3f(x, y, z + size);
-
-	glVertex3f(x + size, y, z);
-	glVertex3f(x + size, y, z + size);
-
-	glVertex3f(x, y + size, z);
-	glVertex3f(x, y + size, z + size);
-
-	glVertex3f(x + size, y + size, z);
-	glVertex3f(x + size, y + size, z + size);
-
-	glVertex3f(x					 , y, z);
-	glVertex3f(x + size, y, z);
-
-	glVertex3f(x					 , y, z + size);
-	glVertex3f(x + size, y, z + size);
-
-	glVertex3f(x					 , y + size , z);
-	glVertex3f(x + size, y + size , z);
-
-	glVertex3f(x					 , y + size , z + size);
-	glVertex3f(x + size, y + size , z + size);
-
-	glVertex3f(x, y						, z);
-	glVertex3f(x, y + size, z);
-
-	glVertex3f(x + size, y					 , z);
-	glVertex3f(x + size, y + size, z);
-
-	glVertex3f(x, y						, z + size);
-	glVertex3f(x, y + size, z + size);
-
-	glVertex3f(x + size, y					 , z + size);
-	glVertex3f(x + size, y + size, z + size);
-
-	glEnd();
-}
-

+ 0 - 163
samples/minecrown/WorldTerrain.h

@@ -1,163 +0,0 @@
-#ifndef __WORLD_TERRAIN_H__
-#define __WORLD_TERRAIN_H__
-
-#include "Crown.h"
-#include "WorldMaterial.h"
-
-using namespace Crown;
-
-#define WORLD_SIZE 512//1024
-#define WORLD_SIZE_H 128
-#define CHUNK_SIZE 16
-#define CHUNKS_COUNT 32 //Deve essere dispari
-#define CHUNKS_COUNT_H (WORLD_SIZE_H/CHUNK_SIZE)
-
-class WorldTerrain;
-
-enum FaceVisibility
-{
-	FV_NONE		= 0,
-	FV_TOP		= 1,
-	FV_BOTTOM	= 2,
-	FV_LEFT		= 4,
-	FV_RIGHT	= 8,
-	FV_FRONT	= 16,
-	FV_BACK		= 32
-};
-
-enum FaceBuffer
-{
-	FB_TOP = 0,
-	FB_BOTTOM = 1,
-	FB_LEFT = 2,
-	FB_RIGHT = 3,
-	FB_FRONT = 4,
-	FB_BACK = 5
-};
-
-struct Block
-{
-	bool opaque;
-	uchar light;
-	uchar faceVisibility;
-};
-
-struct BlockToRender
-{
-	Block* block;
-	Crown::uint x, z, h;
-};
-
-class Chunk {
-
-public:
-	Chunk(WorldTerrain* terrain);
-	~Chunk();
-
-	void Render();
-
-	void Dirty();
-
-	void AssignLocation(Crown::uint x, Crown::uint z, Crown::uint h);
-	void UpdateShouldRender();
-
-	void BlockRemoved(Crown::uint x, Crown::uint z, Crown::uint h);
-	void BlockRevealed(Crown::uint x, Crown::uint z, Crown::uint h);
-
-private:
-	WorldTerrain* mWorldTerrain;
-	int mX, mZ, mH;
-	int mRelX, mRelZ, mRelH;
-	bool mIsDirty;
-	bool mShouldRender;
-	Crown::uint mCandidateBlocks;
-
-	List<BlockToRender> mBlocksToRender;
-
-	VertexBuffer* mVertexBuffer;
-	IndexBuffer* mIndexBuffer;
-
-	VertexData* mVertex;
-	Crown::uint mVertexCount;
-	Crown::uint* mIndices[6];
-	Crown::uint mIndicesCount[6];
-	Crown::uint mIndicesOffsets[6];
-
-	void AddFace(int x, int z, int h, FaceBuffer orientation, uchar light);
-	void AddFace(const FaceMaterial& faceMaterial, Vec3 traslation, float lightFactor, Crown::uint* index, Crown::uint& indicesCount);
-	void RegenerateChunk();
-
-	friend class WorldTerrain;
-};
-
-
-class WorldTerrain
-{
-
-public:
-	
-	WorldTerrain();
-
-	~WorldTerrain();
-
-	void RandomMap(int groundLevel, int seed, int octaves, int freq);
-
-	void Render();
-
-	void SetPlayerPosition(Vec3 newPosition);
-
-	inline Vec3 GetPlayerPosition() const
-	{
-		return mPlayerPosition;
-	}
-
-	void LOL();
-
-	//params
-	void ToggleGrid() { mDrawGrid = !mDrawGrid; }
-
-	void CycleViewDistance();
-
-	//Debug infos
-	int RegeneratedChunks;
-
-private:
-
-	Block mBlocks[WORLD_SIZE][WORLD_SIZE][WORLD_SIZE_H];
-	Chunk* mChunks[CHUNKS_COUNT][CHUNKS_COUNT][CHUNKS_COUNT_H];
-	Texture* mTerrainTexture;
-
-	int mChunkRegenerationSlots;
-
-	Vec3 mPlayerPosition;
-	Crown::uint mChunkX;
-	Crown::uint mChunkZ;
-	Crown::uint mChunkH;
-
-	// Player chunks relative to mChunkX, mChunkZ, mChunkH
-	Crown::uint mPlayerChunkX;
-	Crown::uint mPlayerChunkZ;
-	Crown::uint mPlayerChunkH;
-
-	bool mDrawGrid;
-	int mViewDistance;
-
-
-	void ExtractChunksFromX(Chunk* destChunks[CHUNKS_COUNT][CHUNKS_COUNT_H], Crown::uint x);
-	void ReplaceChunksInX(Chunk* srcChunks[CHUNKS_COUNT][CHUNKS_COUNT_H], Crown::uint x);
-	void ExtractChunksFromZ(Chunk* destChunks[CHUNKS_COUNT][CHUNKS_COUNT_H], Crown::uint z);
-	void ReplaceChunksInZ(Chunk* srcChunks[CHUNKS_COUNT][CHUNKS_COUNT_H], Crown::uint z);
-
-	void RegenerateTerrain();
-
-	void RecalculateVisibleBlocksSides();
-	void RecalculateSunlight();
-	void UpdateVisibleNeighbourBlocks(Crown::uint x, Crown::uint z, Crown::uint h);
-
-	void Clear();
-
-	friend class Chunk;
-};
-
-
-#endif //__WORLD_TERRAIN_H__

+ 0 - 471
samples/minecrown/main.cpp

@@ -1,471 +0,0 @@
-#include "Crown.h"
-#include <time.h>
-#include <cstdlib>
-#include <iostream>
-#include <ft2build.h>
-#include FT_FREETYPE_H
-#include FT_GLYPH_H
-
-#include "WorldTerrain.h"
-#include "perlin.h"
-
-void DrawAxis();
-void DrawGrid(float xStart, float zStart, float xStep, float zStep);
-void DrawCube(float x, float y, float z);
-void DrawVoxelGrid(float xStart, float yStart, float zStart, float xStep, float yStep, float zStep);
-
-using namespace Crown;
-
-MovableCamera* cam;
-WorldTerrain* terrain;
-int groundLevel = 0;
-int seed;
-int octaves = 4, freq = 2;
-int currentFog = 10;
-float fogDensity = 0.1f;
-
-bool attached = true;
-
-class MainScene: public Crown::Scene, EventReceiver {
-
-public:
-
-	MainScene()
-	{
-		GetDevice()->GetEventDispatcher()->RegisterEventReceiver(this);
-		mDevice = GetDevice();
-	}
-
-	virtual ~MainScene()
-	{
-		if (terrain)
-			delete terrain;
-	}
-
-	void HandleEvent(const Event& event)
-	{
-		if (event.event_type == ET_KEYBOARD)
-		{
-			if (event.keyboard.type == KET_RELEASED)
-			{
-				if (event.keyboard.key == KK_ESCAPE)
-				{
-
-					if (mDevice) {
-						mDevice->StopRunning();
-					}
-				}
-
-				if (event.keyboard.key == KK_SPACE) {
-					
-					seed = rand();
-					terrain->RandomMap(groundLevel, seed, octaves, freq);
-				}
-
-				if (event.keyboard.key == KK_UP) {
-					
-					groundLevel += 1;
-					terrain->RandomMap(groundLevel, seed, octaves, freq);
-				}
-
-				if (event.keyboard.key == KK_DOWN) {
-					
-					groundLevel -= 1;
-					terrain->RandomMap(groundLevel, seed, octaves, freq);
-				}
-
-				if (event.keyboard.key == KK_R) {
-					
-					octaves += 1;
-					terrain->RandomMap(groundLevel, seed, octaves, freq);
-				}
-
-				if (event.keyboard.key == KK_F) {
-					
-					if (octaves > 1)
-						octaves -= 1;
-					terrain->RandomMap(groundLevel, seed, octaves, freq);
-				}
-
-				if (event.keyboard.key == KK_T) {
-					
-					freq += 1;
-					terrain->RandomMap(groundLevel, seed, octaves, freq);
-				}
-
-				if (event.keyboard.key == KK_G) {
-					
-					if (freq > 1)
-						freq -= 1;
-					terrain->RandomMap(groundLevel, seed, octaves, freq);
-				}
-
-				if (event.keyboard.key == KK_Y) {
-					
-
-					currentFog+=10;
-					glFogf(GL_FOG_END, currentFog);
-				}
-
-				if (event.keyboard.key == KK_H) {
-					
-					currentFog-=10;
-					glFogf(GL_FOG_END, currentFog);
-				}
-
-				if (event.keyboard.key == KK_1) {
-					
-					terrain->ToggleGrid();
-				}
-
-				if (event.keyboard.key == KK_2) {
-					
-					terrain->CycleViewDistance();
-				}
-
-				if (event.keyboard.key == KK_3) {
-					
-					static bool fogActive = true;
-					if (fogActive)
-						glDisable(GL_FOG);
-					else
-						glEnable(GL_FOG);
-					fogActive = ! fogActive;
-				}
-
-				if (event.keyboard.key == KK_0) {
-					
-					attached = !attached;
-				}
-
-			}
-
-			if (event.keyboard.key == KK_Q)
-			{
-				terrain->LOL();
-			}
-		}
-	}
-
-	virtual void OnLoad() {
-
-		SceneNode* sn = new SceneNode(this, NULL, Vec3(), Angles(), true);
-
-		cam = AddMovableCamera(
-		sn,
-		Vec3((CHUNKS_COUNT+2)/2.0f*CHUNK_SIZE*CubeSize, CHUNKS_COUNT_H*0.7*CHUNK_SIZE*CubeSize, (CHUNKS_COUNT+2)/2.0f*CHUNK_SIZE*CubeSize),
-		//Vec3(0, 1.5*CHUNK_SIZE*CubeSize, 0),
-		Angles(0, 0, 0),
-		true,
-		90.0f,
-		1.59f,
-		true,
-		1.5,
-		1);
-		cam->SetActive(true);
-		cam->SetSpeed(0.1);
-		cam->SetFarClipDistance(150.0f);
-
-		GetDevice()->GetRenderer()->SetClearColor(Color(0.457f, 0.754f, 1.0f, 1.0f));
-
-		srand(time(NULL));
-		seed = rand();
-		terrain = new WorldTerrain();
-		terrain->RandomMap(groundLevel, seed, octaves, freq);
-		
-		timer = Crown::Timer::GetInstance();
-		beforeTime = timer->GetMilliseconds();
-	}
-
-	virtual void RenderScene() {
-
-		Scene::RenderScene();
-
-		cam->Render();
-
-		Mat4 identity;
-		identity.LoadIdentity();
-
-		GetDevice()->GetRenderer()->SetMatrix(MT_MODEL, identity);
-
-		DrawAxis();
-
-		if (attached)
-			terrain->SetPlayerPosition(cam->GetPosition());
-
-		terrain->Render();
-
-		if (timer->GetMilliseconds() - beforeTime > 1000)
-		{
-			Renderer* renderer = mDevice->GetRenderer();
-			Str title = "Fps: " + Str(renderer->GetFPS()) + " - Regenerated Chunks: " + Str(terrain->RegeneratedChunks) + " - Px: " + Str(terrain->GetPlayerPosition().x) + ", Px: " + Str(terrain->GetPlayerPosition().z);
-			terrain->RegeneratedChunks = 0;
-			GetDevice()->GetMainWindow()->SetTitle(title.c_str());
-			beforeTime = timer->GetMilliseconds();
-		}
-	}
-
-	Device* mDevice;
-	Crown::Timer* timer;
-	Crown::ulong beforeTime;
-};
-
-
-int main(int argc, char** argv) {
-
-	int wndW, wndH;
-	wndW = 1024;
-	wndH = 768;
-	bool full = false;
-
-	if (argc == 3) {
-		wndW = atoi(argv[1]);
-		wndH = atoi(argv[2]);
-	}
-
-	Device* device = GetDevice();
-
-
-	if (!device->Init(wndW, wndH, 32, false)) {
-
-		return 0;
-	}
-
-	Renderer* renderer = device->GetRenderer();
-	SceneManager* smgr = device->GetSceneManager();
-	ResourceManager* resman = device->GetResourceManager();
-
-	device->GetMainWindow()->SetTitle("Crown Engine v0.1");
-	device->GetMainWindow()->GetCursorControl()->SetVisible(true);
-	device->GetMainWindow()->SetFullscreen(full);
-
-	Scene* scene = new MainScene();
-	
-	smgr->SelectNextScene(scene);
-
-	device->Run();
-
-	device->Shutdown();
-
-//	Scene* scene = new Scene();
-//
-//	cam = scene->AddMovableCamera(
-//		0,
-//		Vec3((CHUNKS_COUNT+2)/2.0f*CHUNK_SIZE*CubeSize, CHUNKS_COUNT_H*0.7*CHUNK_SIZE*CubeSize, (CHUNKS_COUNT+2)/2.0f*CHUNK_SIZE*CubeSize),
-//		//Vec3(0, 1.5*CHUNK_SIZE*CubeSize, 0),
-//		Angles(0, 0, 0),
-//		Vec3(1, 1, 1),
-//		true,
-//		90.0f,
-//		1.59f,
-//		true,
-//		1.5,
-//		1);
-//	cam->SetActive(true);
-//	cam->SetSpeed(0.1);
-//	cam->SetFarClipDistance(150.0f);
-//
-//	std::cout << "Entity count: " << scene->GetEntityCount() << std::endl;
-//	std::cout << "Light count: " << scene->GetLightCount() << std::endl;
-//	std::cout << "Sizeof RenderWindow: " << sizeof(RenderWindow) << std::endl;
-///*
-//	Material material;
-//	material.mAmbient = Color(0.1, 0.1, 0.1, 1);
-//	material.mDiffuse = Color(1, 1, 1, 1);
-//	material.mSpecular = Color(0, 0, 0, 1);
-//	material.mShininess = 128;
-//	material.mSeparateSpecularColor = true;
-//	material.mTexturing = false;
-//	material.mLighting = true;
-//
-//	renderer->SetMaterial(material);
-//*/
-//	Mat4 identity;
-//	identity.LoadIdentity();
-//
-//	renderer->SetClearColor(Color(0.457f, 0.754f, 1.0f, 1.0f));
-//
-//	Mat4 ortho;
-//	ortho.BuildProjectionOrthoRH(wndW, wndH, 1, -1);
-//
-//	Mat4 perspective;
-//	perspective.BuildProjectionPerspectiveRH(90.0f, 1.59f, 0.1f, 100.0f);
-//
-//	Mat4 text;
-//	text.LoadIdentity();
-//	text.SetTranslation(Vec3(400, 350, 0));
-//
-//
-//	//Crown::Font font;
-//	//Image* testImg = font.LoadFont("tests/font/arialbd.ttf");
-//
-//	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
-//
-//	srand(time(NULL));
-//	seed = rand();
-//	terrain = new WorldTerrain();
-//	terrain->RandomMap(groundLevel, seed, octaves, freq);
-//	//terrain->RandomMap1();
-//
-//	while (device->IsRunning()) {
-//
-//		WindowEventHandler::GetInstance()->ManageEvents();
-//		GetDevice()->GetMainWindow()->GetRenderContext()->MakeCurrent();
-//
-//		// ----------- Begin Scene -----------
-//		renderer->_BeginFrame();
-//
-//		renderer->SetMatrix(MT_PROJECTION, ortho);
-//		//renderer->SetMatrix(MT_MODEL, text);
-//
-//		glDisable(GL_LIGHTING);
-//		glColor3f(1, 1, 1);
-//
-//		cam->Render();
-//
-//		renderer->SetMatrix(MT_MODEL, identity);
-//
-//		DrawAxis();
-//
-//		if (attached)
-//			terrain->SetPlayerPosition(cam->GetPosition());
-//
-//		terrain->Render();
-//
-//		renderer->_EndFrame();
-//		// ----------- End Scene -------------
-//
-//		GetDevice()->GetMainWindow()->Update();
-//		GetDevice()->GetMainWindow()->SetTitle(Str(renderer->GetFPS()).c_str());
-//	}
-//
-//	delete terrain;
-//
-//	device->Shutdown();
-
-	return 0;
-}
-
-void DrawAxis() {
-
-	glBegin(GL_LINES);
-	glColor3f(1, 0, 0);
-	glVertex3f(0, 0, 0);
-	glVertex3f(1000, 0, 0);
-	glColor3f(0, 1, 0);
-	glVertex3f(0, 0, 0);
-	glVertex3f(0, 1000, 0);
-	glColor3f(0, 0, 1);
-	glVertex3f(0, 0, 0);
-	glVertex3f(0, 0, 1000);
-	glEnd();
-}
-
-void DrawGrid(float xStart, float zStart, float xStep, float zStep) {
-
-	glColor3f(.5f, .5f, .5f);
-	const unsigned int steps = 128;
-	for (unsigned int i = 0; i <= steps; i++) {
-		glBegin(GL_LINES);
-		glVertex3f(xStart + xStep * (float)i, -1.0f, zStart);
-		glVertex3f(xStart + xStep * (float)i, -1.0f, zStart-steps*zStep);
-		glEnd();
-
-		glBegin(GL_LINES);
-		glVertex3f(xStart, -1.0f, zStart - zStep * (float)i);
-		glVertex3f(xStart+steps*xStep, -1.0f, zStart - zStep * (float)i);
-		glEnd();
-	}
-}
-
-void DrawCube(float x, float y, float z) {
-
-	glBegin(GL_QUADS);
-
-	
-	//top
-	glColor3f(.3f, .0f, .0f);
-	glVertex3f(x           , y + CubeSize, z);
-	glColor3f(.25f, .0f, .0f);
-	glVertex3f(x + CubeSize, y + CubeSize, z);
-	glColor3f(.3f, .0f, .0f);
-	glVertex3f(x + CubeSize, y + CubeSize, z - CubeSize);
-	glColor3f(.25f, .0f, .0f);
-	glVertex3f(x           , y + CubeSize, z - CubeSize);
-
-	//bottom
-	glColor3f(.0f, .0f, .3f);
-	glVertex3f(x           , y, z);
-	glColor3f(.0f, .0f, .25f);
-	glVertex3f(x           , y, z - CubeSize);
-	glColor3f(.0f, .0f, .3f);
-	glVertex3f(x + CubeSize, y, z - CubeSize);
-	glColor3f(.0f, .0f, .25f);
-	glVertex3f(x + CubeSize, y, z);
-
-	//left
-	glColor3f(.0f, .0f, .3f);
-	glVertex3f(x, y           , z);
-	glColor3f(.0f, .0f, .25f);
-	glVertex3f(x, y + CubeSize, z);
-	glColor3f(.0f, .0f, .3f);
-	glVertex3f(x, y + CubeSize, z - CubeSize);
-	glColor3f(.0f, .0f, .25f);
-	glVertex3f(x, y           , z - CubeSize);
-
-	//right
-	glColor3f(.0f, .0f, .3f);
-	glVertex3f(x + CubeSize, y           , z);
-	glColor3f(.0f, .0f, .25f);
-	glVertex3f(x + CubeSize, y           , z - CubeSize);
-	glColor3f(.0f, .0f, .3f);
-	glVertex3f(x + CubeSize, y + CubeSize, z - CubeSize);
-	glColor3f(.0f, .0f, .25f);
-	glVertex3f(x + CubeSize, y + CubeSize, z);
-
-	//front
-	glColor3f(.0f, .0f, .3f);
-	glVertex3f(x           , y           , z);
-	glColor3f(.0f, .0f, .25f);
-	glVertex3f(x + CubeSize, y           , z);
-	glColor3f(.0f, .0f, .3f);
-	glVertex3f(x + CubeSize, y + CubeSize, z);
-	glColor3f(.0f, .0f, .25f);
-	glVertex3f(x           , y + CubeSize, z);
-
-	//back
-	glColor3f(.0f, .0f, .3f);
-	glVertex3f(x           , y           , z - CubeSize);
-	glColor3f(.0f, .0f, .25f);
-	glVertex3f(x           , y + CubeSize, z - CubeSize);
-	glColor3f(.0f, .0f, .3f);
-	glVertex3f(x + CubeSize, y + CubeSize, z - CubeSize);
-	glColor3f(.0f, .0f, .25f);
-	glVertex3f(x + CubeSize, y           , z - CubeSize);
-
-	glEnd();
-}
-
-void DrawVoxelGrid(float xStart, float yStart, float zStart, float xStep, float yStep, float zStep) {
-
-	glColor3f(.5f, .5f, .5f);
-
-	const unsigned int steps = 16;
-	glBegin(GL_LINES);
-	for (unsigned int i = 0; i <= steps; i++) {
-		
-		for(unsigned int j = 0; j <= steps; j++) {
-			glVertex3f(xStart + xStep * (float)i, j * yStep, zStart);
-			glVertex3f(xStart + xStep * (float)i, j * yStep, zStart-steps*zStep);
-
-			glVertex3f(xStart + xStep * (float)j, yStart, zStart - zStep * (float)i);
-			glVertex3f(xStart + xStep * (float)j, yStart+steps*yStep, zStart - zStep * (float)i);
-
-			glVertex3f(xStart, j * yStep, zStart - zStep * (float)i);
-			glVertex3f(xStart+steps*xStep, j * yStep, zStart - zStep * (float)i);
-		}
-		
-	}
-	glEnd();
-}
-

+ 0 - 238
samples/minecrown/perlin.cpp

@@ -1,238 +0,0 @@
-/* coherent noise function over 1, 2 or 3 dimensions */
-/* (copyright Ken Perlin) */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <math.h>
-
-#include "perlin.h"
-
-#define B SAMPLE_SIZE
-#define BM (SAMPLE_SIZE-1)
-
-#define N 0x1000
-#define NP 12   /* 2^N */
-#define NM 0xfff
-
-#define s_curve(t) ( t * t * (3.0f - 2.0f * t) )
-#define lerp(t, a, b) ( a + t * (b - a) )
-
-#define setup(i,b0,b1,r0,r1)\
-	t = vec[i] + N;\
-	b0 = ((int)t) & BM;\
-	b1 = (b0+1) & BM;\
-	r0 = t - (int)t;\
-	r1 = r0 - 1.0f;
-
-float Perlin::noise1(float arg)
-{
-	int bx0, bx1;
-	float rx0, rx1, sx, t, u, v, vec[1];
-
-	vec[0] = arg;
-
-	if (mStart)
-  {
-    srand(mSeed);
-		mStart = false;
-		init();
-	}
-
-	setup(0, bx0,bx1, rx0,rx1);
-
-	sx = s_curve(rx0);
-
-	u = rx0 * g1[ p[ bx0 ] ];
-	v = rx1 * g1[ p[ bx1 ] ];
-
-	return lerp(sx, u, v);
-}
-
-float Perlin::noise2(float vec[2])
-{
-	int bx0, bx1, by0, by1, b00, b10, b01, b11;
-	float rx0, rx1, ry0, ry1, *q, sx, sy, a, b, t, u, v;
-	int i, j;
-
-	if (mStart)
-  {
-    srand(mSeed);
-		mStart = false;
-		init();
-	}
-
-	setup(0,bx0,bx1,rx0,rx1);
-	setup(1,by0,by1,ry0,ry1);
-
-	i = p[bx0];
-	j = p[bx1];
-
-	b00 = p[i + by0];
-	b10 = p[j + by0];
-	b01 = p[i + by1];
-	b11 = p[j + by1];
-
-	sx = s_curve(rx0);
-	sy = s_curve(ry0);
-
-  #define at2(rx,ry) ( rx * q[0] + ry * q[1] )
-
-	q = g2[b00];
-	u = at2(rx0,ry0);
-	q = g2[b10];
-	v = at2(rx1,ry0);
-	a = lerp(sx, u, v);
-
-	q = g2[b01];
-	u = at2(rx0,ry1);
-	q = g2[b11];
-	v = at2(rx1,ry1);
-	b = lerp(sx, u, v);
-
-	return lerp(sy, a, b);
-}
-
-float Perlin::noise3(float vec[3])
-{
-	int bx0, bx1, by0, by1, bz0, bz1, b00, b10, b01, b11;
-	float rx0, rx1, ry0, ry1, rz0, rz1, *q, sy, sz, a, b, c, d, t, u, v;
-	int i, j;
-
-	if (mStart)
-  {
-    srand(mSeed);
-		mStart = false;
-		init();
-	}
-
-	setup(0, bx0,bx1, rx0,rx1);
-	setup(1, by0,by1, ry0,ry1);
-	setup(2, bz0,bz1, rz0,rz1);
-
-	i = p[ bx0 ];
-	j = p[ bx1 ];
-
-	b00 = p[ i + by0 ];
-	b10 = p[ j + by0 ];
-	b01 = p[ i + by1 ];
-	b11 = p[ j + by1 ];
-
-	t  = s_curve(rx0);
-	sy = s_curve(ry0);
-	sz = s_curve(rz0);
-
-  #define at3(rx,ry,rz) ( rx * q[0] + ry * q[1] + rz * q[2] )
-
-	q = g3[ b00 + bz0 ] ; u = at3(rx0,ry0,rz0);
-	q = g3[ b10 + bz0 ] ; v = at3(rx1,ry0,rz0);
-	a = lerp(t, u, v);
-
-	q = g3[ b01 + bz0 ] ; u = at3(rx0,ry1,rz0);
-	q = g3[ b11 + bz0 ] ; v = at3(rx1,ry1,rz0);
-	b = lerp(t, u, v);
-
-	c = lerp(sy, a, b);
-
-	q = g3[ b00 + bz1 ] ; u = at3(rx0,ry0,rz1);
-	q = g3[ b10 + bz1 ] ; v = at3(rx1,ry0,rz1);
-	a = lerp(t, u, v);
-
-	q = g3[ b01 + bz1 ] ; u = at3(rx0,ry1,rz1);
-	q = g3[ b11 + bz1 ] ; v = at3(rx1,ry1,rz1);
-	b = lerp(t, u, v);
-
-	d = lerp(sy, a, b);
-
-	return lerp(sz, c, d);
-}
-
-void Perlin::normalize2(float v[2])
-{
-	float s;
-
-	s = (float)sqrt(v[0] * v[0] + v[1] * v[1]);
-  s = 1.0f/s;
-	v[0] = v[0] * s;
-	v[1] = v[1] * s;
-}
-
-void Perlin::normalize3(float v[3])
-{
-	float s;
-
-	s = (float)sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
-  s = 1.0f/s;
-
-	v[0] = v[0] * s;
-	v[1] = v[1] * s;
-	v[2] = v[2] * s;
-}
-
-void Perlin::init(void)
-{
-	int i, j, k;
-
-	for (i = 0 ; i < B ; i++)
-  {
-		p[i] = i;
-		g1[i] = (float)((rand() % (B + B)) - B) / B;
-		for (j = 0 ; j < 2 ; j++)
-			g2[i][j] = (float)((rand() % (B + B)) - B) / B;
-		normalize2(g2[i]);
-		for (j = 0 ; j < 3 ; j++)
-			g3[i][j] = (float)((rand() % (B + B)) - B) / B;
-		normalize3(g3[i]);
-	}
-
-	while (--i)
-  {
-		k = p[i];
-		p[i] = p[j = rand() % B];
-		p[j] = k;
-	}
-
-	for (i = 0 ; i < B + 2 ; i++)
-  {
-		p[B + i] = p[i];
-		g1[B + i] = g1[i];
-		for (j = 0 ; j < 2 ; j++)
-			g2[B + i][j] = g2[i][j];
-		for (j = 0 ; j < 3 ; j++)
-			g3[B + i][j] = g3[i][j];
-	}
-
-}
-
-
-float Perlin::perlin_noise_2D(float vec[2])
-{
-  int terms    = mOctaves;
-	float freq   = mFrequency;
-	float result = 0.0f;
-  float amp = mAmplitude;
-
-  vec[0]*=mFrequency;
-  vec[1]*=mFrequency;
-
-	for( int i=0; i<terms; i++ )
-	{
-		result += noise2(vec)*amp;
-		vec[0] *= 2.0f;
-		vec[1] *= 2.0f;
-    amp*=0.5f;
-	}
-
-	return result;
-}
-
-
-
-Perlin::Perlin(int octaves,float freq,float amp,int seed)
-{
-  mOctaves = octaves;
-  mFrequency = freq;
-  mAmplitude = amp;
-  mSeed = seed;
-  mStart = true;
-}
-

+ 0 - 49
samples/minecrown/perlin.h

@@ -1,49 +0,0 @@
-#ifndef PERLIN_H_
-
-#define PERLIN_H_
-
-#include <stdlib.h>
-
-#define SAMPLE_SIZE 1024
-
-class Perlin
-{
-public:
-
-  Perlin(int octaves,float freq,float amp,int seed);
-
-
-  inline float Get(float x,float y)
-  {
-    float vec[2];
-    vec[0] = x;
-    vec[1] = y;
-    return perlin_noise_2D(vec);
-  };
-
-private:
-  void init_perlin(int n,float p);
-  float perlin_noise_2D(float vec[2]);
-
-  float noise1(float arg);
-  float noise2(float vec[2]);
-  float noise3(float vec[3]);
-  void normalize2(float v[2]);
-  void normalize3(float v[3]);
-  void init(void);
-
-  int   mOctaves;
-  float mFrequency;
-  float mAmplitude;
-  int   mSeed;
-
-  int p[SAMPLE_SIZE + SAMPLE_SIZE + 2];
-  float g3[SAMPLE_SIZE + SAMPLE_SIZE + 2][3];
-  float g2[SAMPLE_SIZE + SAMPLE_SIZE + 2][2];
-  float g1[SAMPLE_SIZE + SAMPLE_SIZE + 2];
-  bool  mStart;
-
-};
-
-#endif
-

+ 0 - 697
samples/minecrown/vbo.cpp

@@ -1,697 +0,0 @@
-#include "Crown.h"
-#include <time.h>
-#include <cstdlib>
-#include <iostream>
-#include <ft2build.h>
-#include FT_FREETYPE_H
-#include FT_GLYPH_H
-#include "Types.h"
-
-#define HMSIZE 256
-#define CubeSize 2/3.0f
-
-void DrawAxis();
-void DrawGrid(float xStart, float zStart, float xStep, float zStep);
-void DrawWiredCube(float x, float y, float z);
-void DrawCube(float x, float y, float z);
-void DrawVoxelGrid(float xStart, float yStart, float zStart, float xStep, float yStep, float zStep);
-
-using namespace Crown;
-
-enum Visibility
-{
-	V_Visible,
-	V_Hidden_Opt,
-	V_Hidden,
-};
-
-enum FaceOrientation
-{
-	FO_TOP,
-	FO_BOTTOM,
-	FO_LEFT,
-	FO_RIGHT,
-	FO_FRONT,
-	FO_BACK
-};
-
-struct Block {
-	Visibility visible;
-};
-
-class Chunk {
-
-public:
-	Chunk() {
-		Clear();
-		vb = NULL;
-		ib = NULL;
-	}
-
-	void Clear() {
-
-		mVertexCount = 0;
-		mVertexList.Clear();
-
-		for(int x = 0; x < HMSIZE; x++) {
-			for(int z = 0; z < HMSIZE; z++) {
-				for(int h = 0; h < HMSIZE; h++) {
-					mBlocks[x][z][h].visible = V_Hidden;
-				}
-			}
-		}
-	}
-
-	void Render() {
-
-		vb->MakeCurrent();
-		ib->MakeCurrent();
-		ib->Render(Vec3(0, 0, 0), Vec3(0, 0, 0), 0.0f);
-	}
-
-	void RandomMap() {
-
-		srand(time(NULL));
-		Clear();
-
-		for(int n = 0; n < 100; n++) {
-			int xmin, xmax, zmin, zmax;
-			int a, b;
-			a = rand()%HMSIZE;
-			b = rand()%HMSIZE;
-			xmin = Math::Min(a, b);
-			xmax = Math::Max(a, b);
-
-			a = rand()%HMSIZE;
-			b = rand()%HMSIZE;
-			zmin = Math::Min(a, b);
-			zmax = Math::Max(a, b);
-
-			for(int x = xmin; x < xmax; x++) {
-				for(int z = zmin; z < zmax; z++) {
-
-					int h = 0;
-					while (mBlocks[x][z][h].visible == V_Visible)
-						h++;
-					mBlocks[x][z][h].visible = V_Visible;
-				}
-			}
-		}
-
-		RegenerateVertexList();
-	}
-
-	void RegenerateVertexList() {
-
-		mVertexCount = 0;
-		mVertexList.Clear();
-
-		for(int x = 0; x < HMSIZE; x++) {
-			for(int z = 0; z < HMSIZE; z++) {
-				for(int h = 0; h < HMSIZE; h++) {
-
-					if (mBlocks[x][z][h].visible == V_Visible)
-						GenerateFaces(x, z, h);
-				}
-			}
-		}
-
-		if (!vb)
-			vb = GetDevice()->GetRenderer()->CreateVertexBuffer();
-		if (!ib)
-			ib = GetDevice()->GetRenderer()->CreateIndexBuffer();
-
-		vb->SetVertexData(VBM_COLOR_COORDS, mVertexList.GetData(), mVertexCount);
-
-		List<unsigned int> indexes;
-		for(int i=0; i<mVertexCount; i++)
-			indexes.Append(i);
-		ib->SetIndexData(indexes.GetData(), mVertexCount);
-
-		mVertexList.Clear();
-	}
-
-	void GenerateFaces(int x, int z, int h) {
-
-		AddFace(x, z, h, FO_TOP   , x  , z  , h+1);
-		AddFace(x, z, h, FO_BOTTOM, x  , z  , h-1);
-		AddFace(x, z, h, FO_LEFT  , x-1, z  , h);
-		AddFace(x, z, h, FO_RIGHT , x+1, z  , h);
-		AddFace(x, z, h, FO_FRONT , x  , z+1, h);
-		AddFace(x, z, h, FO_BACK  , x  , z-1, h);
-	}
-
-	void AddFace(int x, int z, int h, FaceOrientation orientation, int x1, int z1, int h1) {
-
-		if (!(x1 < 0 || x1 > HMSIZE-1 || z1 < 0 || z1 > HMSIZE-1 || h1 < 0 || h1 > HMSIZE-1))
-			if (mBlocks[x1][z1][h1].visible == V_Visible)
-				return;
-
-		float xx = x * CubeSize;
-		float zz = z * CubeSize;
-		float hh = h * CubeSize;
-
-		switch (orientation) {
-
-			case FO_TOP:
-				AppendVertex(xx           , hh + CubeSize, zz);
-				AppendColor(.3f, .0f, .0f);
-				AppendVertex(xx + CubeSize, hh + CubeSize, zz);
-				AppendColor(.25f, .0f, .0f);
-				AppendVertex(xx + CubeSize, hh + CubeSize, zz - CubeSize);
-				AppendColor(.3f, .0f, .0f);
-				AppendVertex(xx           , hh + CubeSize, zz - CubeSize);
-				AppendColor(.25f, .0f, .0f);
-				break;
-
-			case FO_BOTTOM:
-				AppendVertex(xx           , hh, zz);
-				AppendColor(.0f, .0f, .3f);
-				AppendVertex(xx           , hh, zz - CubeSize);
-				AppendColor(.0f, .0f, .25f);
-				AppendVertex(xx + CubeSize, hh, zz - CubeSize);
-				AppendColor(.0f, .0f, .3f);
-				AppendVertex(xx + CubeSize, hh, zz);
-				AppendColor(.0f, .0f, .25f);
-				break;
-
-			case FO_LEFT:
-				AppendVertex(xx, hh           , zz);
-				AppendColor(.0f, .0f, .3f);
-				AppendVertex(xx, hh + CubeSize, zz);
-				AppendColor(.0f, .0f, .25f);
-				AppendVertex(xx, hh + CubeSize, zz - CubeSize);
-				AppendColor(.0f, .0f, .3f);
-				AppendVertex(xx, hh           , zz - CubeSize);
-				AppendColor(.0f, .0f, .25f);
-				break;
-
-			case FO_RIGHT:
-				AppendVertex(xx + CubeSize, hh           , zz);
-				AppendColor(.0f, .0f, .3f);
-				AppendVertex(xx + CubeSize, hh           , zz - CubeSize);
-				AppendColor(.0f, .0f, .25f);
-				AppendVertex(xx + CubeSize, hh + CubeSize, zz - CubeSize);
-				AppendColor(.0f, .0f, .3f);
-				AppendVertex(xx + CubeSize, hh + CubeSize, zz);
-				AppendColor(.0f, .0f, .25f);
-				break;
-
-			case FO_FRONT:
-				AppendVertex(xx           , hh           , zz);
-				AppendColor(.0f, .0f, .3f);
-				AppendVertex(xx + CubeSize, hh           , zz);
-				AppendColor(.0f, .0f, .25f);
-				AppendVertex(xx + CubeSize, hh + CubeSize, zz);
-				AppendColor(.0f, .0f, .3f);
-				AppendVertex(xx           , hh + CubeSize, zz);
-				AppendColor(.0f, .0f, .25f);
-				break;
-
-			case FO_BACK:
-				AppendVertex(xx           , hh           , zz - CubeSize);
-				AppendColor(.0f, .0f, .3f);
-				AppendVertex(xx           , hh + CubeSize, zz - CubeSize);
-				AppendColor(.0f, .0f, .25f);
-				AppendVertex(xx + CubeSize, hh + CubeSize, zz - CubeSize);
-				AppendColor(.0f, .0f, .3f);
-				AppendVertex(xx + CubeSize, hh           , zz - CubeSize);
-				AppendColor(.0f, .0f, .25f);
-				break;
-
-		}
-
-		mVertexCount += 4;
-	}
-
-	void AppendVertex(float x, float y, float z) {
-
-		mVertexList.Append(x);
-		mVertexList.Append(y);
-		mVertexList.Append(z);
-	}
-
-	void AppendColor(float r, float g, float b) {
-
-		mVertexList.Append(r);
-		mVertexList.Append(g);
-		mVertexList.Append(b);
-	}
-
-	void Optimize() {
-		
-		for(int x = 1; x < HMSIZE-1; x++) {
-			for(int y = 1; y < HMSIZE-1; y++) {
-				for(int z = 1; z < HMSIZE-1; z++) {
-					if (mBlocks[x][y][z].visible == V_Visible) {
-						if (mBlocks[x-1][y][z].visible != V_Visible && mBlocks[x-1][y][z].visible != V_Hidden_Opt)
-							continue;
-						if (mBlocks[x+1][y][z].visible != V_Visible && mBlocks[x+1][y][z].visible != V_Hidden_Opt)
-							continue;
-						if (mBlocks[x][y-1][z].visible != V_Visible && mBlocks[x][y-1][z].visible != V_Hidden_Opt)
-							continue;
-						if (mBlocks[x][y+1][z].visible != V_Visible && mBlocks[x][y+1][z].visible != V_Hidden_Opt)
-							continue;
-						if (mBlocks[x][y][z-1].visible != V_Visible && mBlocks[x][y][z-1].visible != V_Hidden_Opt)
-							continue;
-						if (mBlocks[x][y][z+1].visible != V_Visible && mBlocks[x][y][z+1].visible != V_Hidden_Opt)
-							continue;
-						mBlocks[x][y][z].visible = V_Hidden_Opt;
-					}
-				}
-			}
-		}
-
-		for(int x = 1; x < HMSIZE-1; x++) {
-			for(int y = 1; y < HMSIZE-1; y++) {
-				for(int z = 1; z < HMSIZE-1; z++) {
-					if (mBlocks[x][y][z].visible == V_Hidden_Opt) {
-						mBlocks[x][y][z].visible = V_Hidden;
-					}
-				}
-			}
-		}
-	}
-
-private:
-
-	Block mBlocks[HMSIZE][HMSIZE][HMSIZE];
-	List<float> mVertexList;
-	int mVertexCount;
-	VertexBuffer* vb;
-	IndexBuffer* ib;
-};
-
-Chunk chunk;
-
-class InputReceiver : public EventReceiver {
-
-public:
-
-	InputReceiver() {
-		mDevice = GetDevice();
-		mDevice->GetEventDispatcher()->RegisterEventReceiver(this);
-	}
-
-	void HandleEvent(const Event& event) {
-
-		if (event.event_type == ET_KEYBOARD) {
-			if (event.keyboard.type == KET_RELEASED) {
-				if (event.keyboard.key == KK_ESCAPE) {
-
-					if (mDevice) {
-						mDevice->StopRunning();
-					}
-				}
-
-				if (event.keyboard.key == KK_SPACE) {
-
-					chunk.RandomMap();
-				}
-			}
-		}
-	}
-
-private:
-
-	Device* mDevice;
-};
-
-int main(int argc, char** argv) {
-
-	int wndW, wndH;
-	wndW = 1280;
-	wndH = 800;
-	bool full = false;
-
-	if (argc == 3) {
-		wndW = atoi(argv[1]);
-		wndH = atoi(argv[2]);
-	}
-
-	Device* device = GetDevice();
-
-
-	if (!device->Init(wndW, wndH, 32, false)) {
-
-		return 0;
-	}
-
-	InputReceiver ir;
-
-	Renderer* renderer = device->GetRenderer();
-	SceneManager* smgr = device->GetSceneManager();
-	ResourceManager* resman = device->GetResourceManager();
-
-	device->GetMainWindow()->SetTitle("Crown Engine v0.1");
-	device->GetMainWindow()->GetCursorControl()->SetVisible(true);
-	device->GetMainWindow()->SetFullscreen(full);
-
-	Scene* scene = new Scene();
-
-	MovableCamera* cam;
-	cam = scene->AddMovableCamera(
-		0,
-		Vec3(0.0f, 3.0f, HMSIZE*CubeSize),
-		Angles(0, 0, 0),
-		Vec3(1, 1, 1),
-		true,
-		90.0f,
-		1.59f,
-		true,
-		0.5,
-		1);
-	cam->SetActive(true);
-	cam->SetSpeed(0.1);
-	cam->SetFarClipDistance(150.0f);
-
-	std::cout << "Entity count: " << scene->GetEntityCount() << std::endl;
-	std::cout << "Light count: " << scene->GetLightCount() << std::endl;
-	std::cout << "Sizeof RenderWindow: " << sizeof(RenderWindow) << std::endl;
-/*
-	Material material;
-	material.mAmbient = Color(0.1, 0.1, 0.1, 1);
-	material.mDiffuse = Color(1, 1, 1, 1);
-	material.mSpecular = Color(0, 0, 0, 1);
-	material.mShininess = 128;
-	material.mSeparateSpecularColor = true;
-	material.mTexturing = false;
-	material.mLighting = true;
-
-	renderer->SetMaterial(material);
-*/
-	Mat4 identity;
-	identity.LoadIdentity();
-
-	renderer->SetClearColor(Color(1.0f, 1.0f, 1.0f, 1.0f));
-
-	Mat4 ortho;
-	ortho.BuildProjectionOrthoRH(wndW, wndH, 1, -1);
-
-	Mat4 perspective;
-	perspective.BuildProjectionPerspectiveRH(90.0f, 1.59f, 0.1f, 100.0f);
-
-	Mat4 text;
-	text.LoadIdentity();
-	text.SetTranslation(Vec3(400, 350, 0));
-
-
-	//Crown::Font font;
-	//Image* testImg = font.LoadFont("tests/font/arialbd.ttf");
-
-	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
-
-	chunk.RandomMap();
-
-
-////struct MyVertex
-//// {
-////   float x, y, z;        //Vertex
-////	 float r, g, b;
-////   //float nx, ny, nz;     //Normal
-////   //float s0, t0;         //Texcoord0
-//// };
-////
-//// MyVertex pvertex[4];
-//// //VERTEX 0
-//// pvertex[0].x = 0.0;
-//// pvertex[0].y = 0.0;
-//// pvertex[0].z = 0.0;
-//// pvertex[0].r = 1.0f;
-//// pvertex[0].g = 0.0f;
-//// pvertex[0].b = 0.0f;
-////
-//// //VERTEX 1
-//// pvertex[1].x = 1.0;
-//// pvertex[1].y = 0.0;
-//// pvertex[1].z = 0.0;
-//// pvertex[1].r = 1.0f;
-//// pvertex[1].g = 1.0f;
-//// pvertex[1].b = 0.0f;
-////
-//// //VERTEX 2
-//// pvertex[2].x = 1.0;
-//// pvertex[2].y = 1.0;
-//// pvertex[2].z = 0.0;
-//// pvertex[2].r = 0.0f;
-//// pvertex[2].g = 1.0f;
-//// pvertex[2].b = 0.0f;
-////
-//// pvertex[3].x = 0.0;
-//// pvertex[3].y = 1.0;
-//// pvertex[3].z = 0.0;
-//// pvertex[3].r = 0.0f;
-//// pvertex[3].g = 1.0f;
-//// pvertex[3].b = 0.0f;
-////
-////
-//// uint VertexVBOID;
-//// uint IndexVBOID;
-////
-//// glGenBuffers(1, &VertexVBOID);
-//// glBindBuffer(GL_ARRAY_BUFFER, VertexVBOID);
-//// glBufferData(GL_ARRAY_BUFFER, sizeof(MyVertex)*4, pvertex, GL_DYNAMIC_DRAW);
-////
-//// ushort pindices[4];
-//// pindices[0] = 0;
-//// pindices[1] = 1;
-//// pindices[2] = 2;
-//// pindices[3] = 3;
-////
-//// glGenBuffers(1, &IndexVBOID);
-//// glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IndexVBOID);
-//// glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(ushort)*4, pindices, GL_DYNAMIC_DRAW);
-////
-//// //Define this somewhere in your header file
-//// #define BUFFER_OFFSET(i) ((char *)NULL + (i))
-
-
-
-	while (device->IsRunning()) {
-
-		WindowEventHandler::GetInstance()->ManageEvents();
-		GetDevice()->GetMainWindow()->GetRenderContext()->MakeCurrent();
-
-		// ----------- Begin Scene -----------
-		renderer->BeginScene();
-
-		renderer->SetMatrix(MT_PROJECTION, ortho);
-		//renderer->SetMatrix(MT_MODEL, text);
-
-		glDisable(GL_LIGHTING);
-		glColor3f(1, 1, 1);
-
-		//glDrawPixels(testImg->GetWidth(), testImg->GetHeight(), GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, testImg->GetBuffer());
-
-		cam->Render();
-
-		//renderer->SetMatrix(MT_PROJECTION, perspective);
-
-		renderer->SetMatrix(MT_MODEL, identity);
-
-		DrawAxis();
-		//DrawGrid(-0.0f, 0.0f, 2/3.0f, 2/3.0f);
-		//DrawVoxelGrid(0.0f, 0.0f, 0.0f, 2/3.0f, 2/3.0f, 2/3.0f);
-
-		chunk.Render();
-		////glBindBuffer(GL_ARRAY_BUFFER, VertexVBOID);
-		////glEnableClientState(GL_VERTEX_ARRAY);
-		////glVertexPointer(3, GL_FLOAT, sizeof(MyVertex), BUFFER_OFFSET(0));   //The starting point of the VBO, for the vertices
-		////
-		////glEnableClientState(GL_COLOR_ARRAY);
-		////glColorPointer(3, GL_FLOAT, sizeof(MyVertex), BUFFER_OFFSET(12));
-
-		////glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IndexVBOID);
-		//////To render, we can either use glDrawElements or glDrawRangeElements
-		//////The is the number of indices. 3 indices needed to make a single triangle
-		////glDrawElements(GL_QUADS, 4, GL_UNSIGNED_SHORT, BUFFER_OFFSET(0));   //The starting point of the IBO
-
-		renderer->EndScene();
-		// ----------- End Scene -------------
-
-		GetDevice()->GetMainWindow()->Update();
-		GetDevice()->GetMainWindow()->SetTitle(Str(renderer->GetFPS()).c_str());
-	}
-
-	//glDeleteBuffers(1, &VertexVBOID);
-	//glDeleteBuffers(1, &IndexVBOID);
-
-
-	//delete testImg;
-
-	device->Shutdown();
-
-	//delete testImg;
-
-	return 0;
-
-}
-
-void DrawAxis() {
-
-	glBegin(GL_LINES);
-	glColor3f(1, 0, 0);
-	glVertex3f(0, 0, 0);
-	glVertex3f(1, 0, 0);
-	glColor3f(0, 1, 0);
-	glVertex3f(0, 0, 0);
-	glVertex3f(0, 1, 0);
-	glColor3f(0, 0, 1);
-	glVertex3f(0, 0, 0);
-	glVertex3f(0, 0, 1);
-	glEnd();
-}
-
-void DrawGrid(float xStart, float zStart, float xStep, float zStep) {
-
-	glColor3f(.5f, .5f, .5f);
-	const unsigned int steps = 128;
-	for (unsigned int i = 0; i <= steps; i++) {
-		glBegin(GL_LINES);
-		glVertex3f(xStart + xStep * (float)i, -1.0f, zStart);
-		glVertex3f(xStart + xStep * (float)i, -1.0f, zStart-steps*zStep);
-		glEnd();
-
-		glBegin(GL_LINES);
-		glVertex3f(xStart, -1.0f, zStart - zStep * (float)i);
-		glVertex3f(xStart+steps*xStep, -1.0f, zStart - zStep * (float)i);
-		glEnd();
-	}
-}
-
-void DrawWiredCube(float x, float y, float z) {
-
-	glColor3f(.5f, .5f, .5f);
-
-	glBegin(GL_LINES);
-
-	glVertex3f(x, y, z);
-	glVertex3f(x, y, z - CubeSize);
-
-	glVertex3f(x + CubeSize, y, z);
-	glVertex3f(x + CubeSize, y, z - CubeSize);
-
-	glVertex3f(x, y + CubeSize, z);
-	glVertex3f(x, y + CubeSize, z - CubeSize);
-
-	glVertex3f(x + CubeSize, y + CubeSize, z);
-	glVertex3f(x + CubeSize, y + CubeSize, z - CubeSize);
-
-	glVertex3f(x					 , y, z);
-	glVertex3f(x + CubeSize, y, z);
-
-	glVertex3f(x					 , y, z - CubeSize);
-	glVertex3f(x + CubeSize, y, z - CubeSize);
-
-	glVertex3f(x					 , y + CubeSize , z);
-	glVertex3f(x + CubeSize, y + CubeSize , z);
-
-	glVertex3f(x					 , y + CubeSize , z - CubeSize);
-	glVertex3f(x + CubeSize, y + CubeSize , z - CubeSize);
-
-	glVertex3f(x, y						, z);
-	glVertex3f(x, y + CubeSize, z);
-
-	glVertex3f(x + CubeSize, y					 , z);
-	glVertex3f(x + CubeSize, y + CubeSize, z);
-
-	glVertex3f(x, y						, z - CubeSize);
-	glVertex3f(x, y + CubeSize, z - CubeSize);
-
-	glVertex3f(x + CubeSize, y					 , z - CubeSize);
-	glVertex3f(x + CubeSize, y + CubeSize, z - CubeSize);
-
-	glEnd();
-}
-
-void DrawCube(float x, float y, float z) {
-
-	glBegin(GL_QUADS);
-
-	
-	//top
-	glColor3f(.3f, .0f, .0f);
-	glVertex3f(x           , y + CubeSize, z);
-	glColor3f(.25f, .0f, .0f);
-	glVertex3f(x + CubeSize, y + CubeSize, z);
-	glColor3f(.3f, .0f, .0f);
-	glVertex3f(x + CubeSize, y + CubeSize, z - CubeSize);
-	glColor3f(.25f, .0f, .0f);
-	glVertex3f(x           , y + CubeSize, z - CubeSize);
-
-	//bottom
-	glColor3f(.0f, .0f, .3f);
-	glVertex3f(x           , y, z);
-	glColor3f(.0f, .0f, .25f);
-	glVertex3f(x           , y, z - CubeSize);
-	glColor3f(.0f, .0f, .3f);
-	glVertex3f(x + CubeSize, y, z - CubeSize);
-	glColor3f(.0f, .0f, .25f);
-	glVertex3f(x + CubeSize, y, z);
-
-	//left
-	glColor3f(.0f, .0f, .3f);
-	glVertex3f(x, y           , z);
-	glColor3f(.0f, .0f, .25f);
-	glVertex3f(x, y + CubeSize, z);
-	glColor3f(.0f, .0f, .3f);
-	glVertex3f(x, y + CubeSize, z - CubeSize);
-	glColor3f(.0f, .0f, .25f);
-	glVertex3f(x, y           , z - CubeSize);
-
-	//right
-	glColor3f(.0f, .0f, .3f);
-	glVertex3f(x + CubeSize, y           , z);
-	glColor3f(.0f, .0f, .25f);
-	glVertex3f(x + CubeSize, y           , z - CubeSize);
-	glColor3f(.0f, .0f, .3f);
-	glVertex3f(x + CubeSize, y + CubeSize, z - CubeSize);
-	glColor3f(.0f, .0f, .25f);
-	glVertex3f(x + CubeSize, y + CubeSize, z);
-
-	//front
-	glColor3f(.0f, .0f, .3f);
-	glVertex3f(x           , y           , z);
-	glColor3f(.0f, .0f, .25f);
-	glVertex3f(x + CubeSize, y           , z);
-	glColor3f(.0f, .0f, .3f);
-	glVertex3f(x + CubeSize, y + CubeSize, z);
-	glColor3f(.0f, .0f, .25f);
-	glVertex3f(x           , y + CubeSize, z);
-
-	//back
-	glColor3f(.0f, .0f, .3f);
-	glVertex3f(x           , y           , z - CubeSize);
-	glColor3f(.0f, .0f, .25f);
-	glVertex3f(x           , y + CubeSize, z - CubeSize);
-	glColor3f(.0f, .0f, .3f);
-	glVertex3f(x + CubeSize, y + CubeSize, z - CubeSize);
-	glColor3f(.0f, .0f, .25f);
-	glVertex3f(x + CubeSize, y           , z - CubeSize);
-
-	glEnd();
-}
-
-void DrawVoxelGrid(float xStart, float yStart, float zStart, float xStep, float yStep, float zStep) {
-
-	glColor3f(.5f, .5f, .5f);
-
-	const unsigned int steps = 16;
-	glBegin(GL_LINES);
-	for (unsigned int i = 0; i <= steps; i++) {
-		
-		for(unsigned int j = 0; j <= steps; j++) {
-			glVertex3f(xStart + xStep * (float)i, j * yStep, zStart);
-			glVertex3f(xStart + xStep * (float)i, j * yStep, zStart-steps*zStep);
-
-			glVertex3f(xStart + xStep * (float)j, yStart, zStart - zStep * (float)i);
-			glVertex3f(xStart + xStep * (float)j, yStart+steps*yStep, zStart - zStep * (float)i);
-
-			glVertex3f(xStart, j * yStep, zStart - zStep * (float)i);
-			glVertex3f(xStart+steps*xStep, j * yStep, zStart - zStep * (float)i);
-		}
-		
-	}
-	glEnd();
-}
-