From 3ba712c7059e4be6764c09a820c2fe4146df1da5 Mon Sep 17 00:00:00 2001 From: Petter Arvidsson Date: Fri, 11 Nov 2016 11:21:56 +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 68d93a0..a2b83be 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 22687ed7d793b7bdc29852d0c61b20571af95fd0 Mon Sep 17 00:00:00 2001 From: Petter Arvidsson Date: Fri, 11 Nov 2016 11:57:13 +0100 Subject: [PATCH 2/4] Fully working version based on latest nanogui - Added our own main loop that follows vsync --- .gitmodules | 3 ++ dependencies/nanogui | 1 + src/main.cpp | 113 +++++++++++++++++++++++++++++++++++++++---- 3 files changed, 108 insertions(+), 9 deletions(-) create mode 160000 dependencies/nanogui diff --git a/.gitmodules b/.gitmodules index a2b83be..1ff6461 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,3 +7,6 @@ [submodule "dependencies/tinyobjloader"] path = dependencies/tinyobjloader url = https://github.com/syoyo/tinyobjloader.git +[submodule "dependencies/nanogui"] + path = dependencies/nanogui + url = https://github.com/wjakob/nanogui.git diff --git a/dependencies/nanogui b/dependencies/nanogui new file mode 160000 index 0000000..ae6fd08 --- /dev/null +++ b/dependencies/nanogui @@ -0,0 +1 @@ +Subproject commit ae6fd08b5f2d6b8cc69b6eb7a7f705db5988e1f4 diff --git a/src/main.cpp b/src/main.cpp index 0cce085..c6e375e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,5 +1,21 @@ +#if defined(NANOGUI_GLAD) + #if defined(NANOGUI_SHARED) && !defined(GLAD_GLAPI_EXPORT) + #define GLAD_GLAPI_EXPORT + #endif + + #include +#else + #if defined(__APPLE__) + #define GLFW_INCLUDE_GLCOREARB + #else + #define GL_GLEXT_PROTOTYPES + #endif +#endif + +#include #include + #if defined(WIN32) #define _WINSOCKAPI_ #include @@ -63,10 +79,8 @@ class Konstructs: public nanogui::Screen { Konstructs(const string &hostname, const string &username, const string &password, - bool debug_mode) : - nanogui::Screen(Eigen::Vector2i(KONSTRUCTS_APP_WIDTH, - KONSTRUCTS_APP_HEIGHT), - KONSTRUCTS_APP_TITLE), + bool debug_mode, + GLFWwindow* window) : hostname(hostname), username(username), password(password), @@ -92,6 +106,12 @@ class Konstructs: public nanogui::Screen { debug_mode(debug_mode), frame(0), click_delay(0) { + initialize(window, true); + int width, height; + glfwGetFramebufferSize(window, &width, &height); + glViewport(0, 0, width, height); + glfwSwapInterval(1); + glfwSwapBuffers(window); using namespace nanogui; performLayout(mNVGContext); @@ -735,6 +755,7 @@ void glfw_error(int error_code, const char *error_string) { cout << "GLFW Error[" << error_code << "]: " << error_string << endl; } +Konstructs *app; int main(int argc, char ** argv) { std::string hostname = "play.konstructs.org"; @@ -784,17 +805,91 @@ int main(int argc, char ** argv) { } try { + glfwSetErrorCallback(glfw_error); - nanogui::init(); + glfwInit(); + + glfwSetTime(0); + + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); + glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); + glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); + + glfwWindowHint(GLFW_SAMPLES, 0); + glfwWindowHint(GLFW_RED_BITS, 8); + glfwWindowHint(GLFW_GREEN_BITS, 8); + glfwWindowHint(GLFW_BLUE_BITS, 8); + glfwWindowHint(GLFW_ALPHA_BITS, 8); + glfwWindowHint(GLFW_STENCIL_BITS, 8); + glfwWindowHint(GLFW_DEPTH_BITS, 24); + glfwWindowHint(GLFW_RESIZABLE, GL_TRUE); + + // Create a GLFWwindow object + GLFWwindow* window = glfwCreateWindow(KONSTRUCTS_APP_WIDTH, KONSTRUCTS_APP_HEIGHT, + KONSTRUCTS_APP_TITLE, nullptr, nullptr); + if (window == nullptr) { + std::cout << "Failed to create GLFW window" << std::endl; + glfwTerminate(); + return -1; + } + glfwMakeContextCurrent(window); + glClearColor(0.2f, 0.25f, 0.3f, 1.0f); + glClear(GL_COLOR_BUFFER_BIT); { - nanogui::ref app = new Konstructs(hostname, username, password, debug_mode); + app = new Konstructs(hostname, username, password, debug_mode, window); + glfwSetCursorPosCallback(window, + [](GLFWwindow *, double x, double y) { + app->cursorPosCallbackEvent(x, y); + }); + + glfwSetMouseButtonCallback(window, + [](GLFWwindow *, int button, int action, int modifiers) { + app->mouseButtonCallbackEvent(button, action, modifiers); + }); + + glfwSetKeyCallback(window, + [](GLFWwindow *, int key, int scancode, int action, int mods) { + app->keyCallbackEvent(key, scancode, action, mods); + }); + + glfwSetCharCallback(window, + [](GLFWwindow *, unsigned int codepoint) { + app->charCallbackEvent(codepoint); + }); + + glfwSetDropCallback(window, + [](GLFWwindow *, int count, const char **filenames) { + app->dropCallbackEvent(count, filenames); + }); + + glfwSetScrollCallback(window, + [](GLFWwindow *, double x, double y) { + app->scrollCallbackEvent(x, y); + }); + + glfwSetFramebufferSizeCallback(window, + [](GLFWwindow *, int width, int height) { + app->resizeCallbackEvent(width, height); + }); + app->drawAll(); app->setVisible(true); - nanogui::mainloop(); - } + while (!glfwWindowShouldClose(window)) { + glfwPollEvents(); + + glClearColor(0.2f, 0.25f, 0.3f, 1.0f); + glClear(GL_COLOR_BUFFER_BIT); - nanogui::shutdown(); + app->drawContents(); + app->drawWidgets(); + + glfwSwapBuffers(window); + } + delete app; + } + glfwTerminate(); } catch (const std::runtime_error &e) { std::string error_msg = std::string("Caught a fatal error: ") + std::string(e.what()); #if defined(WIN32) From 63b00b53ba4e5633d54959bedae57cc7a32255a9 Mon Sep 17 00:00:00 2001 From: Petter Arvidsson Date: Fri, 11 Nov 2016 12:11:31 +0100 Subject: [PATCH 3/4] Fix syntax with astyle --- src/main.cpp | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index c6e375e..afddd70 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -840,39 +840,39 @@ int main(int argc, char ** argv) { { app = new Konstructs(hostname, username, password, debug_mode, window); glfwSetCursorPosCallback(window, - [](GLFWwindow *, double x, double y) { - app->cursorPosCallbackEvent(x, y); - }); + [](GLFWwindow *, double x, double y) { + app->cursorPosCallbackEvent(x, y); + }); glfwSetMouseButtonCallback(window, - [](GLFWwindow *, int button, int action, int modifiers) { - app->mouseButtonCallbackEvent(button, action, modifiers); - }); + [](GLFWwindow *, int button, int action, int modifiers) { + app->mouseButtonCallbackEvent(button, action, modifiers); + }); glfwSetKeyCallback(window, - [](GLFWwindow *, int key, int scancode, int action, int mods) { - app->keyCallbackEvent(key, scancode, action, mods); - }); + [](GLFWwindow *, int key, int scancode, int action, int mods) { + app->keyCallbackEvent(key, scancode, action, mods); + }); glfwSetCharCallback(window, - [](GLFWwindow *, unsigned int codepoint) { - app->charCallbackEvent(codepoint); - }); + [](GLFWwindow *, unsigned int codepoint) { + app->charCallbackEvent(codepoint); + }); glfwSetDropCallback(window, - [](GLFWwindow *, int count, const char **filenames) { - app->dropCallbackEvent(count, filenames); - }); + [](GLFWwindow *, int count, const char **filenames) { + app->dropCallbackEvent(count, filenames); + }); glfwSetScrollCallback(window, - [](GLFWwindow *, double x, double y) { - app->scrollCallbackEvent(x, y); - }); + [](GLFWwindow *, double x, double y) { + app->scrollCallbackEvent(x, y); + }); glfwSetFramebufferSizeCallback(window, - [](GLFWwindow *, int width, int height) { - app->resizeCallbackEvent(width, height); - }); + [](GLFWwindow *, int width, int height) { + app->resizeCallbackEvent(width, height); + }); app->drawAll(); app->setVisible(true); From 715f31bf7a0cf4742346c5d8964e2aec53461a3e Mon Sep 17 00:00:00 2001 From: Petter Arvidsson Date: Fri, 11 Nov 2016 16:29:42 +0100 Subject: [PATCH 4/4] Fix glad build, sort of --- CMakeLists.txt | 8 +++++--- lib/CMakeLists.txt | 2 +- lib/include/gl_includes.h | 4 ++-- src/main.cpp | 16 ---------------- 4 files changed, 8 insertions(+), 22 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6ee15f4..f1ee4d5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,7 +50,7 @@ find_package(ZLIB REQUIRED) include_directories( dependencies/nanogui/include dependencies/nanogui/ext/glfw/include - dependencies/nanogui/ext/glew/include + dependencies/nanogui/ext/glad/include dependencies/nanogui/ext/eigen dependencies/nanogui/ext/nanovg/src dependencies/optional-lite @@ -59,7 +59,9 @@ include_directories( FILE( GLOB SOURCE_FILES - src/*.cpp) + src/*.cpp + dependencies/nanogui/ext/glad/src/glad.c + ) add_executable(konstructs ${SOURCE_FILES}) @@ -67,7 +69,7 @@ set(konstructs_LIBS konstructs-lib ${ZLIB_LIBRARIES} nanogui ${NANOGUI_EXTRA_LIBS} - glfw + glfw ) if(WIN32 OR MINGW) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 15f60a1..22a4f1a 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -29,7 +29,7 @@ find_package(ZLIB REQUIRED) include_directories( ${ZLIB_INCLUDE_DIRS} ../dependencies/nanogui/ext/glfw/include - ../dependencies/nanogui/ext/glew/include + ../dependencies/nanogui/ext/glad/include ../dependencies/nanogui/ext/eigen ../dependencies/lodepng ../dependencies/optional-lite diff --git a/lib/include/gl_includes.h b/lib/include/gl_includes.h index 3751e65..590f94b 100644 --- a/lib/include/gl_includes.h +++ b/lib/include/gl_includes.h @@ -4,8 +4,8 @@ #if defined(__APPLE__) #define GLFW_INCLUDE_GLCOREARB #elif defined(WIN32) - #define GLEW_STATIC - #include + #include + #include #else #define GL_GLEXT_PROTOTYPES #endif diff --git a/src/main.cpp b/src/main.cpp index afddd70..06bf565 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,19 +1,3 @@ -#if defined(NANOGUI_GLAD) - #if defined(NANOGUI_SHARED) && !defined(GLAD_GLAPI_EXPORT) - #define GLAD_GLAPI_EXPORT - #endif - - #include -#else - #if defined(__APPLE__) - #define GLFW_INCLUDE_GLCOREARB - #else - #define GL_GLEXT_PROTOTYPES - #endif -#endif - -#include - #include #if defined(WIN32)