diff --git a/.gitmodules b/.gitmodules index 68d93a0..1ff6461 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 @@ -10,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/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/dependencies/nanogui b/dependencies/nanogui index 2ff9e9c..ae6fd08 160000 --- a/dependencies/nanogui +++ b/dependencies/nanogui @@ -1 +1 @@ -Subproject commit 2ff9e9c29960e7477ecf6fd968139c25c01d3311 +Subproject commit ae6fd08b5f2d6b8cc69b6eb7a7f705db5988e1f4 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 0cce085..06bf565 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,5 +1,5 @@ - #include + #if defined(WIN32) #define _WINSOCKAPI_ #include @@ -63,10 +63,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 +90,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 +739,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 +789,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(); - nanogui::shutdown(); + glClearColor(0.2f, 0.25f, 0.3f, 1.0f); + glClear(GL_COLOR_BUFFER_BIT); + + 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)