From fd7a46a14b9f90fd6faff677fdd7ba8cd4b02e7e Mon Sep 17 00:00:00 2001 From: Stefan Berggren Date: Sun, 3 Dec 2017 21:32:53 +0100 Subject: [PATCH 1/4] Remove nanogui submodule. --- .gitmodules | 3 --- dependencies/nanogui | 1 - 2 files changed, 4 deletions(-) delete mode 160000 dependencies/nanogui diff --git a/.gitmodules b/.gitmodules index 211a380..6ff9320 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,3 @@ -[submodule "dependencies/nanogui"] - path = dependencies/nanogui - url = https://github.com/konstructs/nanogui.git [submodule "dependencies/lodepng"] path = dependencies/lodepng url = https://github.com/lvandeve/lodepng.git diff --git a/dependencies/nanogui b/dependencies/nanogui deleted file mode 160000 index 2ff9e9c..0000000 --- a/dependencies/nanogui +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 2ff9e9c29960e7477ecf6fd968139c25c01d3311 From b5925aa881ff7a8a6c4192c2ade802f1d6abcfc3 Mon Sep 17 00:00:00 2001 From: Stefan Berggren Date: Sun, 3 Dec 2017 21:34:31 +0100 Subject: [PATCH 2/4] Add glfw 3.2.1 submodule. --- .gitmodules | 3 +++ dependencies/glfw | 1 + 2 files changed, 4 insertions(+) create mode 160000 dependencies/glfw diff --git a/.gitmodules b/.gitmodules index 6ff9320..0ee5cd5 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,3 +10,6 @@ [submodule "dependencies/simpleini"] path = dependencies/simpleini url = https://github.com/brofield/simpleini.git +[submodule "dependencies/glfw"] + path = dependencies/glfw + url = https://github.com/glfw/glfw.git diff --git a/dependencies/glfw b/dependencies/glfw new file mode 160000 index 0000000..999f355 --- /dev/null +++ b/dependencies/glfw @@ -0,0 +1 @@ +Subproject commit 999f3556fdd80983b10051746264489f2cb1ef16 From c3a0f52d1931f7b6d74f7ebfa2d866b2ed555815 Mon Sep 17 00:00:00 2001 From: Stefan Berggren Date: Sun, 3 Dec 2017 22:09:15 +0100 Subject: [PATCH 3/4] Add GLEW and Eigen submodules. Also, remove some more nano code. --- .gitmodules | 6 ++++++ CMakeLists.txt | 20 ++++++-------------- dependencies/eigen | 1 + dependencies/glew | 1 + lib/CMakeLists.txt | 6 +++--- 5 files changed, 17 insertions(+), 17 deletions(-) create mode 160000 dependencies/eigen create mode 160000 dependencies/glew diff --git a/.gitmodules b/.gitmodules index 0ee5cd5..1986c7e 100644 --- a/.gitmodules +++ b/.gitmodules @@ -13,3 +13,9 @@ [submodule "dependencies/glfw"] path = dependencies/glfw url = https://github.com/glfw/glfw.git +[submodule "dependencies/glew"] + path = dependencies/glew + url = https://github.com/nigels-com/glew.git +[submodule "dependencies/eigen"] + path = dependencies/eigen + url = https://github.com/libigl/eigen.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 6ee15f4..26efdae 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,13 +27,9 @@ if(MSVC) endif() #----------------------------------------------------------------------- -# Nano GUI +# GLFW #----------------------------------------------------------------------- -SET(GLFW_USE_OPTIMUS_HPG ON CACHE BOOL "Build glfw with HPG (High Performance Graphics) on windows") -option(NANOGUI_BUILD_PYTHON OFF) -option(NANOGUI_BUILD_EXAMPLE OFF) -option(NANOGUI_BUILD_SHARED OFF) -add_subdirectory(dependencies/nanogui) +set(GLFW_USE_OPTIMUS_HPG ON CACHE BOOL "Build glfw with HPG (High Performance Graphics) on windows") #----------------------------------------------------------------------- # Konstructs lib @@ -43,16 +39,13 @@ add_subdirectory(lib) #----------------------------------------------------------------------- # Misc #----------------------------------------------------------------------- - set(CMAKE_BUILD_TYPE Debug) - find_package(ZLIB REQUIRED) + include_directories( - dependencies/nanogui/include - dependencies/nanogui/ext/glfw/include - dependencies/nanogui/ext/glew/include - dependencies/nanogui/ext/eigen - dependencies/nanogui/ext/nanovg/src + dependencies/glfw/include + dependencies/glew/include + dependencies/eigen dependencies/optional-lite dependencies/tinyobjloader lib/include) @@ -66,7 +59,6 @@ add_executable(konstructs ${SOURCE_FILES}) set(konstructs_LIBS konstructs-lib ${ZLIB_LIBRARIES} - nanogui ${NANOGUI_EXTRA_LIBS} glfw ) diff --git a/dependencies/eigen b/dependencies/eigen new file mode 160000 index 0000000..1f05f51 --- /dev/null +++ b/dependencies/eigen @@ -0,0 +1 @@ +Subproject commit 1f05f51517ec4fd91eed711e0f89e97a7c028c0e diff --git a/dependencies/glew b/dependencies/glew new file mode 160000 index 0000000..2af38d8 --- /dev/null +++ b/dependencies/glew @@ -0,0 +1 @@ +Subproject commit 2af38d87be3b2e69fda484dc0cd3f03b905da6dd diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 736314c..4b34dc0 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -28,9 +28,9 @@ find_package(ZLIB REQUIRED) include_directories( ${ZLIB_INCLUDE_DIRS} - ../dependencies/nanogui/ext/glfw/include - ../dependencies/nanogui/ext/glew/include - ../dependencies/nanogui/ext/eigen + ../dependencies/glfw/include + ../dependencies/glew/include + ../dependencies/eigen ../dependencies/lodepng ../dependencies/optional-lite ../dependencies/tinyobjloader From e466abdef5fd1461dbcd75350f4eb02e9bd403e4 Mon Sep 17 00:00:00 2001 From: Stefan Berggren Date: Sun, 3 Dec 2017 22:56:31 +0100 Subject: [PATCH 4/4] Remove more nano stuff --- src/main.cpp | 140 ++++----------------------------------------------- 1 file changed, 10 insertions(+), 130 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index a2b6530..db384d6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,5 +1,4 @@ -#include #if defined(WIN32) #define _WINSOCKAPI_ #include @@ -7,10 +6,10 @@ #else #include #endif -#include #include #include #include +#include "GLFW/glfw3.h" #include "tiny_obj_loader.h" #include "optional.hpp" #include "matrix.h" @@ -44,12 +43,9 @@ void print_usage(); void glfw_error(int error_code, const char *error_string); -class Konstructs: public nanogui::Screen { +class Konstructs { public: - Konstructs(Settings settings) : - nanogui::Screen(Eigen::Vector2i(settings.client.window_width, - settings.client.window_height), - KONSTRUCTS_APP_TITLE), + Konstructs(Settings settings, GLFWwindow* mGLFWWindow) : player(0, Vector3f(0.0f, 0.0f, 0.0f), 0.0f, 0.0f), px(0), py(0), model_factory(blocks), @@ -72,8 +68,6 @@ class Konstructs: public nanogui::Screen { click_delay(0), settings(settings) { - using namespace nanogui; - performLayout(mNVGContext); glfwSetInputMode(mGLFWWindow, GLFW_CURSOR, GLFW_CURSOR_DISABLED); Settings::Server server = settings.server; if (server.username.size() > 0 && server.password.size() > 0 && server.address.size() > 0) { @@ -121,7 +115,7 @@ class Konstructs: public nanogui::Screen { // Clicking at the window captures the mouse pointer glfwSetInputMode(mGLFWWindow, GLFW_CURSOR, GLFW_CURSOR_DISABLED); } - return Screen::mouseButtonEvent(p, button, down, modifiers); + // TODO return Screen::mouseButtonEvent(p, button, down, modifiers); } virtual bool keyboardEvent(int key, int scancode, int action, int modifiers) { @@ -168,12 +162,7 @@ class Konstructs: public nanogui::Screen { return true; } - virtual void draw(NVGcontext *ctx) { - Screen::draw(ctx); - } - virtual void drawContents() { - using namespace nanogui; update_fps(&fps); frame++; if (client.is_connected()) { @@ -215,52 +204,8 @@ class Konstructs: public nanogui::Screen { private: - /** This function uses nanovg to print text on top of the screen. This is - * used for both the debug screen and messages sent from the server. - */ void print_top_text() { - int width, height; - glfwGetFramebufferSize(mGLFWWindow, &width, &height); - - ostringstream os; - if (debug_text_enabled) { - double frame_fps = 1.15 / frame_time; - os << std::fixed << std::setprecision(2); - os << "Server: " << settings.server.address - << " user: " << settings.server.username - << " x: " << player.position(0) - << " y: " << player.position(1) - << " z: " << player.position(2) - << std::endl; - if(looking_at) { - auto l = *looking_at; - uint8_t direction = direction_from_vector(l.first.position, l.second.position); - uint8_t rotation = rotation_from_vector(direction, player.camera_direction()); - os << "Pointing at x: " << l.second.position(0) << ", " - << "y: " << l.second.position(1) << ", " - << "z: " << l.second.position(2) << ", " - << "dir: " << direction_to_string[direction] << ", " - << "rot: " << rotation_to_string[rotation] - << std::endl; - } else { - os << "Pointing at nothing." << std::endl; - } - os << "View distance: " << view_distance << " (" << radius << "/" << client.get_loaded_radius() << ") " - << "faces: " << faces << "(" << max_faces << ") " - << "FPS: " << fps.fps << "(" << frame_fps << ")" << endl; - os << "Chunks: " << world.size() << " " - << "models: " << chunk_shader.size() << endl; - os << "Model factory, waiting: " << model_factory.waiting() << " " - << "created: " << model_factory.total_created() << " " - << "empty: " << model_factory.total_empty() << " " - << "total: " << model_factory.total() << endl; - - } - - glActiveTexture(GL_TEXTURE0); - nvgFontBlur(mNVGContext, 0.8f); - nvgFontSize(mNVGContext, 20.0f); - nvgTextBox(mNVGContext, 10, 20, width - 10, os.str().c_str(), NULL); + // Dummy } int translate_button(int button) { @@ -642,65 +587,7 @@ class Konstructs: public nanogui::Screen { void show_menu(int state, string message) { - using namespace nanogui; - - glfwSetInputMode(mGLFWWindow, GLFW_CURSOR, GLFW_CURSOR_NORMAL); - glActiveTexture(GL_TEXTURE0); - - FormHelper *gui = new FormHelper(this); - window = gui->addWindow({0,0}, "Main Menu"); - gui->setFixedSize({125, 20}); - - if (state == 1) { - // Popup message - - auto dlg = new MessageDialog(this, MessageDialog::Type::Warning, "Server connection", message); - } else if (state == 2) { - // Popup message with connect/cancel buttons. - - auto dlg = new MessageDialog(this, MessageDialog::Type::Warning, - "Server connection", message, - "Reconnect", "Cancel", true); - dlg->setCallback([&](int result) { - if (result == 0) { - window->dispose(); - menu_state = false; - setup_connection(); - } - }); - } - - #if defined(KONSTRUCTS_SINGLE_PLAYER) - gui->addGroup("Singleplayer game"); - gui->addButton("Play", [&]() { - settings.server.username = "singleplayer"; - settings.server.password = "singleplayer"; - settings.server.address = "localhost"; - window->dispose(); - menu_state = false; - setup_connection(); - }); - gui->addGroup("Multiplayer"); - #endif - gui->addVariable("Server address", settings.server.address); - gui->addVariable("Username", settings.server.username); - gui->addVariable("Password", settings.server.password); - gui->addButton("Connect", [&]() { - if (settings.server.username != "" && - settings.server.password != "" && - settings.server.address != "") { - // Note: The mouse pointer is intentionally not locked here. - // See: setup_connection() - window->dispose(); - menu_state = false; - setup_connection(); - save_settings(settings); - } - }); - - window->center(); - performLayout(mNVGContext); - menu_state = true; + // Dummy } void setup_connection() { @@ -742,7 +629,6 @@ class Konstructs: public nanogui::Screen { double last_frame; bool menu_state; bool debug_text_enabled; - nanogui::Window *window; uint32_t frame; uint32_t faces; uint32_t max_faces; @@ -839,17 +725,11 @@ int main(int argc, char ** argv) { } try { - glfwSetErrorCallback(glfw_error); - nanogui::init(); - - { - nanogui::ref app = new Konstructs(settings); - app->drawAll(); - app->setVisible(true); - nanogui::mainloop(); + if (!glfwInit()) { + glfwSetErrorCallback(glfw_error); + GLFWwindow* window = glfwCreateWindow(640, 480, "My Title", NULL, NULL); + Konstructs* app = new Konstructs(settings, window); } - - nanogui::shutdown(); } catch (const std::runtime_error &e) { std::string error_msg = std::string("Caught a fatal error: ") + std::string(e.what()); #if defined(WIN32)