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

Commit

Permalink
imgui: Upgrade to docking branch, split init function to allow for im…
Browse files Browse the repository at this point in the history
…gui configuration

middle title
  • Loading branch information
PatchMixolydic committed Jan 11, 2019
1 parent f59ce56 commit dcce45d
Show file tree
Hide file tree
Showing 14 changed files with 7,648 additions and 1,749 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set(CMAKE_CXX_STANDARD 17)

set(GLFW_INC_DIRECTORY "/usr/include" CACHE FILEPATH "GLFW's include directory")

include_directories(${GLFW_INC_DIRECTORY}/GLFW thirdparty/ ${PROJECT_SOURCE_DIR}/include)
include_directories(${GLFW_INC_DIRECTORY}/GLFW thirdparty/ include/ include/blackcomb/imgui)

add_library(blackcomb thirdparty/glad.c src/base/Window.cpp include/blackcomb/base/Window.h src/renderer/Shader.cpp include/blackcomb/renderer/Shader.h src/renderer/Mesh.cpp include/blackcomb/renderer/Mesh.h src/renderer/Texture.cpp include/blackcomb/renderer/Texture.h include/blackcomb/misc/BlackcombException.h src/misc/BlackcombException.cpp src/renderer/Model.cpp include/blackcomb/renderer/Model.h src/entities/BaseEntity.cpp include/blackcomb/entities/BaseEntity.h src/entities/RenderableEntity.cpp include/blackcomb/entities/RenderableEntity.h src/entities/Camera.cpp include/blackcomb/entities/Camera.h src/entities/FreeMoveCamera.cpp include/blackcomb/entities/FreeMoveCamera.h src/input/MouseWatcher.cpp include/blackcomb/input/MouseWatcher.h src/misc/BlackcombUtils.cpp include/blackcomb/misc/BlackcombUtils.h src/renderer/TextureAtlas.cpp include/blackcomb/renderer/TextureAtlas.h include/blackcomb/misc/Coords.h src/misc/Coords.cpp src/misc/RNG.cpp include/blackcomb/misc/RNG.h src/base/AppBase.cpp include/blackcomb/base/AppBase.h
src/imgui/imgui.cpp src/imgui/imgui_draw.cpp src/imgui/imgui_widgets.cpp src/imgui/imgui_impl_glfw.cpp src/imgui/imgui_impl_opengl3.cpp src/imgui/imgui_demo.cpp
Expand Down
21 changes: 0 additions & 21 deletions include/blackcomb/imgui/LICENSE.txt

This file was deleted.

2 changes: 2 additions & 0 deletions include/blackcomb/imgui/Wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ namespace blackcomb::imgui {
*/
class Wrapper {
public:
static void createContext();
static void simpleConfig();
static void initialize(GLFWwindow* windowPtr, const char* glslVersion = nullptr, bool installCallbacks = true);
static void beginFrame();
static void render();
Expand Down
355 changes: 273 additions & 82 deletions include/blackcomb/imgui/imgui.h

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions include/blackcomb/imgui/imgui_impl_glfw.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// [X] Platform: Gamepad support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'.
// [x] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'. FIXME: 3 cursors types are missing from GLFW.
// [X] Platform: Keyboard arrays indexed using GLFW_KEY_* codes, e.g. ImGui::IsKeyPressed(GLFW_KEY_SPACE).
// [X] Platform: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'.

// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
// If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp.
Expand Down
1 change: 1 addition & 0 deletions include/blackcomb/imgui/imgui_impl_opengl3.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

// Implemented features:
// [X] Renderer: User texture binding. Use 'GLuint' OpenGL texture identifier as void*/ImTextureID. Read the FAQ about ImTextureID in imgui.cpp.
// [X] Renderer: Multi-viewport support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'.

// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
// If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp.
Expand Down
332 changes: 281 additions & 51 deletions include/blackcomb/imgui/imgui_internal.h

Large diffs are not rendered by default.

48 changes: 41 additions & 7 deletions src/imgui/Wrapper.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,44 @@
#include <glfw3.h>
#include <blackcomb/imgui/Wrapper.h>

#include "blackcomb/imgui/Wrapper.h"

namespace blackcomb::imgui {
/**
* Initialize the imgui context and bindings.
* @param windowPtr The handle of the window to draw to
* @param glslVersion The GLSL version, defined as in a shader file (ie. "#version 150"), or nullptr for imgui's default.
* @param installCallbacks Whether or not imgui should register its callbacks with OpenGL.
* Creates the ImGui context. Call this before any other ImGui function!
*/
void Wrapper::initialize(GLFWwindow* windowPtr, const char* glslVersion, bool installCallbacks) {
// Setup context
void Wrapper::createContext() {
IMGUI_CHECKVERSION();
ImGui::CreateContext();
}

/**
* Sets up a simple, workable default configuration if you don't want to bother with it yourself.
* Enables viewports (you can remove UI panels from the window), docking (tabs/tiling), and the dark theme.
*/
void Wrapper::simpleConfig() {
ImGuiIO& io = ImGui::GetIO(); (void)io;
io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Panels can be removed from the window
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // You can tile panels or turn them into tabs

// Use dark theme by default because this engine is RAD
ImGui::StyleColorsDark();

// However, we should disable background opacity and corner rounding so we don't get visual discrepancies
ImGuiStyle& style = ImGui::GetStyle();
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) {
style.WindowRounding = 0.0f;
style.Colors[ImGuiCol_WindowBg].w = 1.0f;
}
}

/**
* Initialize the imgui context and bindings. Call after createContext and after configuring ImGui
* @param windowPtr The handle of the window to draw to
* @param glslVersion The GLSL version, defined as in a shader file (ie. "#version 150"), or nullptr for imgui's default.
* @param installCallbacks Whether or not imgui should register its callbacks with OpenGL.
*/
void Wrapper::initialize(GLFWwindow* windowPtr, const char* glslVersion, bool installCallbacks) {
// Setup platform bindings
ImGui_ImplGlfw_InitForOpenGL(windowPtr, installCallbacks);
ImGui_ImplOpenGL3_Init(glslVersion);
Expand All @@ -23,7 +48,7 @@ namespace blackcomb::imgui {
* Should be called each frame you are drawing an imgui object, before rendering anything.
* Informs imgui that a new frame has begun.
*/
void Wrapper::beginFrame(){
void Wrapper::beginFrame() {
// Start the Dear ImGui frame
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
Expand All @@ -38,6 +63,15 @@ namespace blackcomb::imgui {
// Rendering
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());

// Update other viewports
ImGuiIO& io = ImGui::GetIO(); (void)io;
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) {
GLFWwindow* contextBackup = glfwGetCurrentContext();
ImGui::UpdatePlatformWindows();
ImGui::RenderPlatformWindowsDefault();
glfwMakeContextCurrent(contextBackup);
}
}

/**
Expand Down
Loading

0 comments on commit dcce45d

Please sign in to comment.