Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImGui Prototype #1283

Draft
wants to merge 4 commits into
base: imgui
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,19 @@ option(F3D_MODULE_EXR "OpenEXR images module" OFF)
# Use externals
option(F3D_USE_EXTERNAL_CXXOPTS "Use external cxxopts dependency" OFF)
option(F3D_USE_EXTERNAL_NLOHMANN_JSON "Use external nlohmann_json dependency" OFF)
option(F3D_USE_EXTERNAL_IMGUI "Use external imgui dependency" OFF)

if (F3D_USE_EXTERNAL_CXXOPTS)
find_package(cxxopts REQUIRED)
endif ()
if (F3D_USE_EXTERNAL_NLOHMANN_JSON)
find_package(nlohmann_json REQUIRED)
endif ()
if (F3D_USE_EXTERNAL_IMGUI)
find_package(imgui REQUIRED)
else()
add_subdirectory(external/imgui)
endif ()

# VTK dependency
# Optional components should list VTK modules
Expand Down
1 change: 1 addition & 0 deletions application/F3DOptionsParser.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ void ConfigurationOptions::GetOptions(F3DAppOptions& appOptions, f3d::options& o
this->DeclareOption(grp0, "config", "", "Specify the configuration file to use. absolute/relative path or filename/filestem to search in configuration file locations.", appOptions.UserConfigFile, LocalHasDefaultNo, MayHaveConfig::NO , "<filePath/filename/fileStem>");
this->DeclareOption(grp0, "dry-run", "", "Do not read the configuration file", appOptions.DryRun, HasDefault::YES, MayHaveConfig::NO );
this->DeclareOption(grp0, "no-render", "", "Do not render anything and quit right after loading the first file, use with --verbose to recover information about a file.", appOptions.NoRender, HasDefault::YES, MayHaveConfig::YES );
this->DeclareOption(grp0, "imgui", "", "Use the experimental window with ImGUI", appOptions.ImGui, HasDefault::YES, MayHaveConfig::YES);
this->DeclareOption(grp0, "max-size", "", "Maximum size in Mib of a file to load, negative value means unlimited", appOptions.MaxSize, HasDefault::YES, MayHaveConfig::YES, "<size in Mib>");
this->DeclareOption(grp0, "load-plugins", "", "List of plugins to load separated with a comma", appOptions.Plugins, LocalHasDefaultNo, MayHaveConfig::YES, "<paths or names>");
this->DeclareOption(grp0, "scan-plugins", "", "Scan some directories for plugins (result can be incomplete)");
Expand Down
1 change: 1 addition & 0 deletions application/F3DOptionsParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ struct F3DAppOptions
std::string InteractionTestPlayFile = "";
bool NoBackground = false;
bool NoRender = false;
bool ImGui = false;
double RefThreshold = 50;
double MaxSize = -1.0;

Expand Down
19 changes: 19 additions & 0 deletions application/F3DStarter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,13 @@ int F3DStarter::Start(int argc, char** argv)
{
this->Internals->Engine = std::make_unique<f3d::engine>(f3d::window::Type::NONE);
}
else if (this->Internals->AppOptions.ImGui)
{
f3d::log::warn("ImGui support is experimental.");
this->Internals->Engine = std::make_unique<f3d::engine>(f3d::window::Type::IMGUI);
f3d::interactor& interactor = this->Internals->Engine->getInteractor();
interactor.start();
}
else
{
bool offscreen =
Expand Down Expand Up @@ -328,6 +335,18 @@ int F3DStarter::Start(int argc, char** argv)

f3d::log::debug("========== Rendering ==========");

// TODO
if (this->Internals->AppOptions.ImGui) {
f3d::interactor& interactor = this->Internals->Engine->getInteractor();

this->Render();

// We implement a custom interactor which only has a basic event loop
interactor.start();

return EXIT_SUCCESS;
}

if (!this->Internals->AppOptions.NoRender)
{
f3d::window& window = this->Internals->Engine->getWindow();
Expand Down
29 changes: 29 additions & 0 deletions external/imgui/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Dear ImGui
add_library(imgui INTERFACE)
add_library(imgui::imgui ALIAS imgui)

set(IMGUI_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(IMGUI_SOURCES
imgui_demo.cpp
imgui_draw.cpp
imgui_tables.cpp
imgui_widgets.cpp
imgui.cpp

imconfig.h
imgui_internal.h
imgui.h
imstb_rectpack.h
imstb_textedit.h
imstb_truetype.h

# integration with opengl
backends/imgui_impl_opengl3.cpp
backends/imgui_impl_opengl3.h
backends/imgui_impl_opengl3_loader.h
)
list(TRANSFORM IMGUI_SOURCES PREPEND ${IMGUI_DIR}/)

target_sources(imgui INTERFACE ${IMGUI_SOURCES})
target_include_directories(imgui INTERFACE ${IMGUI_DIR})
target_include_directories(imgui INTERFACE ${IMGUI_DIR}/backends)
995 changes: 995 additions & 0 deletions external/imgui/backends/imgui_impl_opengl3.cpp

Large diffs are not rendered by default.

67 changes: 67 additions & 0 deletions external/imgui/backends/imgui_impl_opengl3.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// dear imgui: Renderer Backend for modern OpenGL with shaders / programmatic pipeline
// - Desktop GL: 2.x 3.x 4.x
// - Embedded GL: ES 2.0 (WebGL 1.0), ES 3.0 (WebGL 2.0)
// This needs to be used along with a Platform Backend (e.g. GLFW, SDL, Win32, custom..)

// Implemented features:
// [X] Renderer: User texture binding. Use 'GLuint' OpenGL texture identifier as void*/ImTextureID. Read the FAQ about ImTextureID!
// [X] Renderer: Large meshes support (64k+ vertices) with 16-bit indices (Desktop OpenGL only).
// [X] Renderer: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'.

// About WebGL/ES:
// - You need to '#define IMGUI_IMPL_OPENGL_ES2' or '#define IMGUI_IMPL_OPENGL_ES3' to use WebGL or OpenGL ES.
// - This is done automatically on iOS, Android and Emscripten targets.
// - For other targets, the define needs to be visible from the imgui_impl_opengl3.cpp compilation unit. If unsure, define globally or in imconfig.h.

// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
// Learn about Dear ImGui:
// - FAQ https://dearimgui.com/faq
// - Getting Started https://dearimgui.com/getting-started
// - Documentation https://dearimgui.com/docs (same as your local docs/ folder).
// - Introduction, links and more at the top of imgui.cpp

// About GLSL version:
// The 'glsl_version' initialization parameter should be nullptr (default) or a "#version XXX" string.
// On computer platform the GLSL version default to "#version 130". On OpenGL ES 3 platform it defaults to "#version 300 es"
// Only override if your GL version doesn't handle this GLSL version. See GLSL version table at the top of imgui_impl_opengl3.cpp.

#pragma once
#include "imgui.h" // IMGUI_IMPL_API
#ifndef IMGUI_DISABLE

// Backend API
IMGUI_IMPL_API bool ImGui_ImplOpenGL3_Init(const char* glsl_version = nullptr);
IMGUI_IMPL_API void ImGui_ImplOpenGL3_Shutdown();
IMGUI_IMPL_API void ImGui_ImplOpenGL3_NewFrame();
IMGUI_IMPL_API void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data);

// (Optional) Called by Init/NewFrame/Shutdown
IMGUI_IMPL_API bool ImGui_ImplOpenGL3_CreateFontsTexture();
IMGUI_IMPL_API void ImGui_ImplOpenGL3_DestroyFontsTexture();
IMGUI_IMPL_API bool ImGui_ImplOpenGL3_CreateDeviceObjects();
IMGUI_IMPL_API void ImGui_ImplOpenGL3_DestroyDeviceObjects();

// Specific OpenGL ES versions
//#define IMGUI_IMPL_OPENGL_ES2 // Auto-detected on Emscripten
//#define IMGUI_IMPL_OPENGL_ES3 // Auto-detected on iOS/Android

// You can explicitly select GLES2 or GLES3 API by using one of the '#define IMGUI_IMPL_OPENGL_LOADER_XXX' in imconfig.h or compiler command-line.
#if !defined(IMGUI_IMPL_OPENGL_ES2) \
&& !defined(IMGUI_IMPL_OPENGL_ES3)

// Try to detect GLES on matching platforms
#if defined(__APPLE__)
#include <TargetConditionals.h>
#endif
#if (defined(__APPLE__) && (TARGET_OS_IOS || TARGET_OS_TV)) || (defined(__ANDROID__))
#define IMGUI_IMPL_OPENGL_ES3 // iOS, Android -> GL ES 3, "#version 300 es"
#elif defined(__EMSCRIPTEN__) || defined(__amigaos4__)
#define IMGUI_IMPL_OPENGL_ES2 // Emscripten -> GL ES 2, "#version 100"
#else
// Otherwise imgui_impl_opengl3_loader.h will be used.
#endif

#endif

#endif // #ifndef IMGUI_DISABLE
Loading