Skip to content

Commit

Permalink
closer to basic compile
Browse files Browse the repository at this point in the history
  • Loading branch information
nmwsharp committed Nov 21, 2017
1 parent 238119e commit facf50e
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 37 deletions.
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -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
Expand Down
16 changes: 7 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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)
14 changes: 14 additions & 0 deletions deps/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion deps/glad/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 2.8.9)

# subdirectories
add_subdirectory(src)
target_include_directories(polyscope PRIVATE "include")
2 changes: 2 additions & 0 deletions deps/glad/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ add_library(
glad.c
)


target_include_directories(glad PRIVATE "../include")
16 changes: 9 additions & 7 deletions include/polyscope/gl_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
#include <string>
#include <vector>

#include <shaders.h>
#include <vector2.h>
#include <vector3.h>
#include <utilities.h>
#include <colors.h>
#include <colormaps.h>
#include "shaders.h"
// #include <vector2.h>
// #include <vector3.h>
// #include <utilities.h>
// #include <colors.h>
// #include <colormaps.h>

/*
// The drawing modes available
enum class DrawMode {Points, LinesAdjacency, Triangles, TrianglesAdjacency, Patches, IndexedTriangles, Lines, IndexedLines, IndexedLineStrip, IndexedLinesAdjacency, IndexedLineStripAdjacency};
Expand Down Expand Up @@ -155,7 +157,7 @@ class GLProgram {
static GLuint commonShaderHandle; // functions accessible to all shaders
};

*/

// Utility functions
void printShaderInfoLog(GLuint shaderHandle);
Expand Down
3 changes: 1 addition & 2 deletions include/polyscope/polyscope.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "polyscope/options.h"
#include "polyscope/gl_utils.h"

namespace polyscope {

Expand All @@ -14,8 +15,6 @@ namespace polyscope {
void show();




// === Global variables ===
namespace state {

Expand Down
8 changes: 5 additions & 3 deletions src/gl_utils.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#include <gl_utils.h>
#include <shaders/common.h>
#include <polyscope/gl_utils.h>
#include <polyscope/shaders/common.h>

#include <stdexcept>
#include <iostream>

using std::cout; using std::endl;

/*
GLuint GLProgram::commonShaderHandle = 0;
GLProgram::GLProgram(const VertShader* vShader, const FragShader* fShader, DrawMode dm)
Expand Down Expand Up @@ -901,7 +903,7 @@ void GLProgram::draw() {
checkGLError();
}

*/

// Helper function to print compile logs
void printShaderInfoLog(GLuint shaderHandle) {
Expand Down
35 changes: 22 additions & 13 deletions src/polyscope.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
#include "polyscope/polyscope.h"

#include <iostream>


#include "polyscope/gl_utils.h"

#ifdef _WIN32
#undef APIENTRY
#define GLFW_EXPOSE_NATIVE_WIN32
#define GLFW_EXPOSE_NATIVE_WGL
#include <GLFW/glfw3native.h>
#undef APIENTRY
#define GLFW_EXPOSE_NATIVE_WIN32
#define GLFW_EXPOSE_NATIVE_WGL
#include <GLFW/glfw3native.h>
#endif

#include <imgui.h>
Expand Down Expand Up @@ -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


Expand All @@ -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
Expand All @@ -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;
}
Expand All @@ -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.
Expand Down Expand Up @@ -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);
}


Expand Down

0 comments on commit facf50e

Please sign in to comment.