diff --git a/Makefile b/Makefile index f2bc4399..245dead4 100755 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ LDFLAGS := -g -Wl #--------------------------------------------------------------------------------- # Any extra libraries you wish to link with your project #--------------------------------------------------------------------------------- -LIBS := -lGL -lGLU -lSDL +LIBS := -lglfw -lGL -lGLU -lSDL -lXrandr #--------------------------------------------------------------------------------- # list of directories containing libraries, this must be the top level containing diff --git a/TODO b/TODO index 0e680931..59630afb 100755 --- a/TODO +++ b/TODO @@ -1,5 +1,6 @@ - Multi-biome: Working on - Improve multi-biome display + - Bugs with biomes at (1;0) and (0;1) - Fix cube selected from a biome to another one bug - Fix problem in manageEvents - Big map && map generation diff --git a/include/scene.h b/include/scene.h index e1b38ec3..a8a5bd09 100644 --- a/include/scene.h +++ b/include/scene.h @@ -39,6 +39,7 @@ class Scene { void display(); void loadTextures(); + void drawBiomes(); void drawField(); void lockMouse(); diff --git a/source/main.cpp b/source/main.cpp index ece699cf..5dcf46fa 100755 --- a/source/main.cpp +++ b/source/main.cpp @@ -23,8 +23,7 @@ #include #include -#include -#include +#include #include "sdlglutils.h" @@ -37,6 +36,8 @@ #include "scene.h" int main(int argc, char *argv[]) { + glfwInit(); + // Init SDL and OpenGL initSDL(); initOpenGL(); @@ -48,6 +49,8 @@ int main(int argc, char *argv[]) { // Stop SDL SDL_Quit(); + glfwTerminate(); + return 0; } diff --git a/source/scene.cpp b/source/scene.cpp index b0474b3f..dcd233de 100644 --- a/source/scene.cpp +++ b/source/scene.cpp @@ -24,8 +24,7 @@ #include #include -#include -#include +#include #include "sdlglutils.h" @@ -55,7 +54,7 @@ bool Scene::intersectionLinePlane(vect3D normal, vect3D planePoint, vect3D lineO float k = p2 / p1; - if(k < 0) return false; + if((k < 0) || (k > 5)) return false; vect3D i; // Intersection point @@ -267,12 +266,24 @@ void Scene::exec() { m_cont = true; + double lastTime = glfwGetTime(); + int nbFrames = 0; + while(m_cont) { + // Measure speed + double currentTime = glfwGetTime(); + nbFrames++; + if(currentTime - lastTime >= 1.0) { + cout << 1000.0/double(nbFrames) << " ms/frame" << endl; + nbFrames = 0; + lastTime += 1.0; + } + manageEvents(); animate(); draw(); display(); - cout << "Selected: (" << selectedCube->x() << ";" << selectedCube->y() << ";" << selectedCube->z() << ") face: " << (int)selectedCube->selectedFace() << endl; + //cout << "Current biome: (" << biome->x() << ";" << biome->y() << ";" << biome->z() << ")" << endl; } unlockMouse(); @@ -401,10 +412,7 @@ void Scene::loadTextures() { m_textures["bedrock"] = loadTexture("textures/bedrock.bmp"); } -void Scene::drawField() { - // Turn on textures - glEnable(GL_TEXTURE_2D); - +void Scene::drawBiomes() { biome = findNearestBiome(player->x(), player->y(), player->z()); biome->draw(); testCubes(biome->cubes()); @@ -412,6 +420,19 @@ void Scene::drawField() { findNearestBiome(player->x() + 16, player->y(), player->z())->draw(); findNearestBiome(player->x(), player->y() + 16, player->z())->draw(); findNearestBiome(player->x() + 16, player->y() + 16, player->z())->draw(); + findNearestBiome(player->x() - 16, player->y() + 16, player->z())->draw(); + + findNearestBiome(player->x() - 16, player->y(), player->z())->draw(); + findNearestBiome(player->x(), player->y() - 16, player->z())->draw(); + findNearestBiome(player->x() - 16, player->y() - 16, player->z())->draw(); + findNearestBiome(player->x() + 16, player->y() - 16, player->z())->draw(); +} + +void Scene::drawField() { + drawBiomes(); + + // Turn on textures + glEnable(GL_TEXTURE_2D); glPushMatrix(); glLoadIdentity();