Skip to content
This repository has been archived by the owner on Dec 28, 2022. It is now read-only.

Commit

Permalink
simplified cmake, fixed visual studio entry point, imgui demo
Browse files Browse the repository at this point in the history
  • Loading branch information
aarcangeli committed Nov 18, 2018
1 parent dae2fc6 commit 39b88d4
Show file tree
Hide file tree
Showing 16 changed files with 142 additions and 82 deletions.
10 changes: 7 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ project(ChristmasLightShowMaker)

set(CMAKE_CXX_STANDARD 11)
set(ROOT_DIRECTORY ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${ROOT_DIRECTORY}/cmake")
include(Variables)
set(OUTPUT_DIRECTORY ${ROOT_DIRECTORY}/bin)

add_subdirectory(libs/glad)
if (MINGW)
# remove dependencies to libstdc++-6.dll, libgcc_s_dw2-1.dll, libwinpthread-1.dll
set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++ -static")
endif ()

add_subdirectory(libs)
add_subdirectory(src)
14 changes: 0 additions & 14 deletions cmake/Variables.cmake

This file was deleted.

10 changes: 0 additions & 10 deletions cmake/find_directories_containing.cmake

This file was deleted.

2 changes: 0 additions & 2 deletions cmake/glad.cmake

This file was deleted.

14 changes: 0 additions & 14 deletions cmake/glfw.cmake

This file was deleted.

5 changes: 0 additions & 5 deletions cmake/imgui.cmake

This file was deleted.

32 changes: 32 additions & 0 deletions libs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# verify submodules
IF (NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/glfw/CMakeLists.txt")
message(FATAL_ERROR "oops. Missing glfw. had you cloned with --recursive?")
endif ()
IF (NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/imgui/imgui.h")
message(FATAL_ERROR "oops. Missing imgui. had you cloned with --recursive?")
endif ()

# configure 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)
set(GLFW_INSTALL OFF CACHE BOOL "GLFW lib only")
add_subdirectory(glfw)

# configure imgui
find_package(OpenGL REQUIRED)
set(
IMGUI_SOURCES
imgui/imgui.cpp
imgui/imgui_widgets.cpp
imgui/imgui_draw.cpp
imgui/imgui_demo.cpp
imgui/examples/imgui_impl_glfw.cpp
imgui/examples/imgui_impl_opengl3.cpp
)
add_library(imgui ${IMGUI_SOURCES})
target_include_directories(imgui PUBLIC imgui imgui/examples ${OPENGL_INCLUDE_DIR})
target_compile_definitions(imgui PRIVATE -DIMGUI_IMPL_OPENGL_LOADER_GLAD)
target_link_libraries(imgui glad glfw ${GLFW_LIBRARIES})

add_subdirectory(glad)
3 changes: 2 additions & 1 deletion libs/glad/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
include_directories(include)
# generated by glad webservice (https://glad.dav1d.de/)
add_library(glad src/glad.c)
target_include_directories(glad PUBLIC include)
5 changes: 0 additions & 5 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
include(find_directories_containing)

find_directories_containing(HEADERS "*.h")
include_directories(${HEADERS})

add_subdirectory(core)
add_subdirectory(model)
add_subdirectory(editor)
Expand Down
1 change: 1 addition & 0 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
file(GLOB_RECURSE SOURCES *.cpp)
add_library(core ${SOURCES})
target_include_directories(core PUBLIC .)
2 changes: 2 additions & 0 deletions src/editor/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
file(GLOB_RECURSE SOURCES *.cpp)
add_library(editor ${SOURCES})
target_include_directories(editor PUBLIC .)
target_link_libraries(editor core imgui)
1 change: 1 addition & 0 deletions src/model/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
file(GLOB_RECURSE SOURCES *.cpp)
add_library(model ${SOURCES})
target_include_directories(model PUBLIC .)
target_link_libraries(model core)
86 changes: 82 additions & 4 deletions src/showmaker/Application.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#include "Application.h"

#include <cstdio>
#include "core.h"
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include "imgui.h"
#include "imgui_impl_glfw.h"
#include "imgui_impl_opengl3.h"

using namespace sm;

Expand All @@ -11,6 +15,10 @@ static void glfw_error_callback(int error, const char *description) {
}

int Application::runLoop() {
return 0;
}

int Application::demoWindow() {
GLFWwindow *window;

glfwSetErrorCallback(glfw_error_callback);
Expand All @@ -30,17 +38,87 @@ int Application::runLoop() {
glfwSwapInterval(1);
gladLoadGLLoader((GLADloadproc) glfwGetProcAddress);

IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO &io = ImGui::GetIO();
io.IniFilename = "showmaker.ini";

ImGui_ImplGlfw_InitForOpenGL(window, true);
ImGui_ImplOpenGL3_Init(nullptr);
ImGui::StyleColorsDark();
//ImGui::StyleColorsClassic();

bool show_demo_window = true;
bool show_another_window = false;
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);

while (!glfwWindowShouldClose(window)) {
/* Render here */
/* Poll for and process events */
glfwPollEvents();

// Start the Dear ImGui frame
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();

if (show_demo_window)
ImGui::ShowDemoWindow(&show_demo_window);

// 2. Show a simple window that we create ourselves. We use a Begin/End pair to created a named window.
{
static float f = 0.0f;
static int counter = 0;

ImGui::Begin("Hello, world!"); // Create a window called "Hello, world!" and append into it.

ImGui::Text("This is some useful text."); // Display some text (you can use a format strings too)
ImGui::Checkbox("Demo Window", &show_demo_window); // Edit bools storing our window open/close state
ImGui::Checkbox("Another Window", &show_another_window);

ImGui::SliderFloat("float", &f, 0.0f, 1.0f); // Edit 1 float using a slider from 0.0f to 1.0f
ImGui::ColorEdit3("clear color", (float *) &clear_color); // Edit 3 floats representing a color

if (ImGui::Button(
"Button")) // Buttons return true when clicked (most widgets return true when edited/activated)
counter++;
ImGui::SameLine();
ImGui::Text("counter = %d", counter);

ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
ImGui::End();
}

// 3. Show another simple window.
if (show_another_window) {
ImGui::Begin("Another Window",
&show_another_window); // Pass a pointer to our bool variable (the window will have a closing button that will clear the bool when clicked)
ImGui::Text("Hello from another window!");
if (ImGui::Button("Close Me"))
show_another_window = false;
ImGui::End();
}

// Rendering
ImGui::Render();
int display_w, display_h;
glfwMakeContextCurrent(window);
glfwGetFramebufferSize(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_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());

/* Swap front and back buffers */
glfwMakeContextCurrent(window);
glfwSwapBuffers(window);

/* Poll for and process events */
glfwPollEvents();
}

// Cleanup
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();

glfwDestroyWindow(window);
glfwTerminate();
return 0;
}
2 changes: 2 additions & 0 deletions src/showmaker/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const int WINDOW_HEIGHT = 720;
class Application {
public:
int runLoop();

int demoWindow();
};

}
Expand Down
24 changes: 1 addition & 23 deletions src/showmaker/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,26 +1,4 @@
include(glfw)
include(imgui)
include(glad)

find_package(OpenGL REQUIRED)

include_directories(
${IMGUI_INCLUDE_DIR}
${GLFW_INCLUDE_DIR}
${OPENGL_INCLUDE_DIR}
${GLAD_INCLUDE_DIR}
)

file(GLOB_RECURSE SOURCES *.cpp)
add_executable(showmaker WIN32 ${SOURCES})

target_link_libraries(
showmaker
core
editor
glfw ${GLFW_LIBRARIES}
opengl32
glad
)

target_link_libraries(showmaker editor imgui)
install(TARGETS showmaker RUNTIME DESTINATION ${OUTPUT_DIRECTORY})
13 changes: 12 additions & 1 deletion src/showmaker/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
#include "Application.h"

int main() {
#ifdef WIN32

#include "Windows.h"

int WinMain(HINSTANCE hInst, HINSTANCE hPreInst, LPSTR nCmdLine, int nCmdShow)
#endif
#ifndef WIN32
int main(int argc, char **argv)
#endif

{
sm::Application app;
return app.demoWindow();
return app.runLoop();
}

0 comments on commit 39b88d4

Please sign in to comment.