From facf50eb98d07a9dcdbead60dc991d3615abccc3 Mon Sep 17 00:00:00 2001 From: Nick Sharp Date: Tue, 21 Nov 2017 12:09:25 -0500 Subject: [PATCH] closer to basic compile --- .gitmodules | 4 ++-- CMakeLists.txt | 16 +++++++--------- deps/CMakeLists.txt | 14 ++++++++++++++ deps/glad/CMakeLists.txt | 2 +- deps/glad/src/CMakeLists.txt | 2 ++ include/polyscope/gl_utils.h | 16 +++++++++------- include/polyscope/polyscope.h | 3 +-- src/gl_utils.cpp | 8 +++++--- src/polyscope.cpp | 35 ++++++++++++++++++++++------------- 9 files changed, 63 insertions(+), 37 deletions(-) create mode 100644 deps/CMakeLists.txt diff --git a/.gitmodules b/.gitmodules index 729b3955..6b989ed4 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,5 +1,5 @@ -[submodule "deps/imgui"] - path = deps/imgui +[submodule "deps/imgui/imgui"] + path = deps/imgui/imgui url = https://github.com/ocornut/imgui.git [submodule "deps/glfw"] path = deps/glfw diff --git a/CMakeLists.txt b/CMakeLists.txt index c7e3d9e9..48720706 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,22 +1,15 @@ -cmake_minimum_required(VERSION 2.8.9) +cmake_minimum_required(VERSION 3.1) project(polyscope) ### Policy settings cmake_policy(SET CMP0054 NEW) # don't implicitly dereference inside if() - ### Configure output locations set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) -### Do anything needed for dependencies and bring their stuff in to scope -add_subdirectory(deps) - -### Includes from this project -include_directories(include) - ### Compiler options set( CMAKE_EXPORT_COMPILE_COMMANDS 1 ) # Emit a compile flags file to support completion engines @@ -51,5 +44,10 @@ else() message( FATAL_ERROR "Unrecognized compiler [${CMAKE_CXX_COMPILER_ID}]" ) endif() +### Add things for this project +add_subdirectory(src) +target_include_directories(polyscope PUBLIC "include") + +### Do anything needed for dependencies and bring their stuff in to scope +add_subdirectory(deps) -add_subdirectory(src) \ No newline at end of file diff --git a/deps/CMakeLists.txt b/deps/CMakeLists.txt new file mode 100644 index 00000000..7c5db426 --- /dev/null +++ b/deps/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 2.8.9) + +## Glad +add_subdirectory(glad) + +## GLFW +set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE) +set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE) +set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) +add_subdirectory(glfw) +target_include_directories(polyscope PRIVATE "glfw/include") + +## Imgui +add_subdirectory(imgui) \ No newline at end of file diff --git a/deps/glad/CMakeLists.txt b/deps/glad/CMakeLists.txt index f221d1a8..3d27f161 100644 --- a/deps/glad/CMakeLists.txt +++ b/deps/glad/CMakeLists.txt @@ -1,4 +1,4 @@ cmake_minimum_required(VERSION 2.8.9) -# subdirectories add_subdirectory(src) +target_include_directories(polyscope PRIVATE "include") \ No newline at end of file diff --git a/deps/glad/src/CMakeLists.txt b/deps/glad/src/CMakeLists.txt index d7b1adbf..5196febb 100644 --- a/deps/glad/src/CMakeLists.txt +++ b/deps/glad/src/CMakeLists.txt @@ -6,3 +6,5 @@ add_library( glad.c ) + +target_include_directories(glad PRIVATE "../include") \ No newline at end of file diff --git a/include/polyscope/gl_utils.h b/include/polyscope/gl_utils.h index 57428f4f..1b6d99a1 100644 --- a/include/polyscope/gl_utils.h +++ b/include/polyscope/gl_utils.h @@ -10,12 +10,14 @@ #include #include -#include -#include -#include -#include -#include -#include +#include "shaders.h" +// #include +// #include +// #include +// #include +// #include + +/* // The drawing modes available enum class DrawMode {Points, LinesAdjacency, Triangles, TrianglesAdjacency, Patches, IndexedTriangles, Lines, IndexedLines, IndexedLineStrip, IndexedLinesAdjacency, IndexedLineStripAdjacency}; @@ -155,7 +157,7 @@ class GLProgram { static GLuint commonShaderHandle; // functions accessible to all shaders }; - +*/ // Utility functions void printShaderInfoLog(GLuint shaderHandle); diff --git a/include/polyscope/polyscope.h b/include/polyscope/polyscope.h index 4ee13df1..c6f758c8 100644 --- a/include/polyscope/polyscope.h +++ b/include/polyscope/polyscope.h @@ -1,6 +1,7 @@ #pragma once #include "polyscope/options.h" +#include "polyscope/gl_utils.h" namespace polyscope { @@ -14,8 +15,6 @@ namespace polyscope { void show(); - - // === Global variables === namespace state { diff --git a/src/gl_utils.cpp b/src/gl_utils.cpp index dc155395..7d8f0909 100644 --- a/src/gl_utils.cpp +++ b/src/gl_utils.cpp @@ -1,10 +1,12 @@ -#include -#include +#include +#include #include +#include using std::cout; using std::endl; +/* GLuint GLProgram::commonShaderHandle = 0; GLProgram::GLProgram(const VertShader* vShader, const FragShader* fShader, DrawMode dm) @@ -901,7 +903,7 @@ void GLProgram::draw() { checkGLError(); } - +*/ // Helper function to print compile logs void printShaderInfoLog(GLuint shaderHandle) { diff --git a/src/polyscope.cpp b/src/polyscope.cpp index 8fa80793..3f065cf5 100644 --- a/src/polyscope.cpp +++ b/src/polyscope.cpp @@ -1,12 +1,15 @@ #include "polyscope/polyscope.h" +#include + + #include "polyscope/gl_utils.h" #ifdef _WIN32 -#undef APIENTRY -#define GLFW_EXPOSE_NATIVE_WIN32 -#define GLFW_EXPOSE_NATIVE_WGL -#include + #undef APIENTRY + #define GLFW_EXPOSE_NATIVE_WIN32 + #define GLFW_EXPOSE_NATIVE_WGL + #include #endif #include @@ -433,6 +436,11 @@ void ImGui_ImplGlfwGL3_NewFrame() ImGui::NewFrame(); } +// Small callback function for GLFW errors +void error_print_callback(int error, const char* description) { + std::cerr << "GLFW emitted error: " << description << std::endl; +} + } // private namespace @@ -446,17 +454,18 @@ void init() { } // === Initialize glfw - glfwSetErrorCallback(error_callback); - if (!glfwInit()) - return 1; + glfwSetErrorCallback(error_print_callback); + if (!glfwInit()) { + throw std::runtime_error(options::printPrefix + "ERROR: Failed to initialize glfw"); + } glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); #if __APPLE__ glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); #endif - GLFWwindow* window = glfwCreateWindow(1280, 720, options::programName, NULL, NULL); - glfwMakeContextCurrent(window); + g_Window = glfwCreateWindow(1280, 720, options::programName.c_str(), NULL, NULL); + glfwMakeContextCurrent(g_Window); glfwSwapInterval(1); // Enable vsync // === Initialize openGL @@ -477,7 +486,7 @@ void init() { // Set up ImGUI glfw bindings - ImGui_ImplGlfwGL3_Init(window, true); + ImGui_ImplGlfwGL3_Init(g_Window, true); state::initialized = true; } @@ -489,7 +498,7 @@ void show() { ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); // Main loop - while (!glfwWindowShouldClose(window)) + while (!glfwWindowShouldClose(g_Window)) { // You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs. // - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application. @@ -527,12 +536,12 @@ void show() { // Rendering int display_w, display_h; - glfwGetFramebufferSize(window, &display_w, &display_h); + glfwGetFramebufferSize(g_Window, &display_w, &display_h); glViewport(0, 0, display_w, display_h); glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w); glClear(GL_COLOR_BUFFER_BIT); ImGui::Render(); - glfwSwapBuffers(window); + glfwSwapBuffers(g_Window); }