Skip to content

Commit

Permalink
dear imgui added. Cursor management has been disabled. I'm rushing th…
Browse files Browse the repository at this point in the history
…e release...
  • Loading branch information
CedricGuillemet committed Jan 6, 2019
1 parent 771d19b commit 8e3d465
Show file tree
Hide file tree
Showing 16 changed files with 30,566 additions and 2 deletions.
15 changes: 15 additions & 0 deletions PathTracer/PathTracer.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\thirdparty\glew\src\glew.c" />
<ClCompile Include="..\thirdparty\imgui\imgui.cpp" />
<ClCompile Include="..\thirdparty\imgui\imgui_draw.cpp" />
<ClCompile Include="..\thirdparty\imgui\imgui_impl_glfw.cpp" />
<ClCompile Include="..\thirdparty\imgui\imgui_impl_opengl3.cpp" />
<ClCompile Include="..\thirdparty\imgui\imgui_widgets.cpp" />
<ClCompile Include="src\Camera.cpp" />
<ClCompile Include="src\GPUBVH.cpp" />
<ClCompile Include="src\hdrloader.cpp" />
Expand All @@ -34,6 +39,14 @@
<ClCompile Include="src\TiledRenderer.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\thirdparty\imgui\imconfig.h" />
<ClInclude Include="..\thirdparty\imgui\imgui.h" />
<ClInclude Include="..\thirdparty\imgui\imgui_impl_glfw.h" />
<ClInclude Include="..\thirdparty\imgui\imgui_impl_opengl3.h" />
<ClInclude Include="..\thirdparty\imgui\imgui_internal.h" />
<ClInclude Include="..\thirdparty\imgui\imstb_rectpack.h" />
<ClInclude Include="..\thirdparty\imgui\imstb_textedit.h" />
<ClInclude Include="..\thirdparty\imgui\imstb_truetype.h" />
<ClInclude Include="src\Camera.h" />
<ClInclude Include="src\GPUBVH.h" />
<ClInclude Include="src\hdrloader.h" />
Expand Down Expand Up @@ -167,6 +180,7 @@
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;GLM_FORCE_RADIANS;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalUsingDirectories>
</AdditionalUsingDirectories>
<AdditionalIncludeDirectories>$(SolutionDir)/thirdparty/imgui;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand Down Expand Up @@ -207,6 +221,7 @@
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;GLM_FORCE_RADIANS;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalUsingDirectories>
</AdditionalUsingDirectories>
<AdditionalIncludeDirectories>$(SolutionDir)/thirdparty/imgui;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand Down
42 changes: 42 additions & 0 deletions PathTracer/PathTracer.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
<Filter Include="Shaders\Tiled">
<UniqueIdentifier>{7a682e03-3e14-4f4f-a8f4-cbfd8c84b998}</UniqueIdentifier>
</Filter>
<Filter Include="imgui">
<UniqueIdentifier>{d85fb95f-f94b-4d16-ae7e-9b134062548d}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\Camera.cpp">
Expand Down Expand Up @@ -63,6 +66,21 @@
<ClCompile Include="src\hdrloader.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\thirdparty\imgui\imgui.cpp">
<Filter>imgui</Filter>
</ClCompile>
<ClCompile Include="..\thirdparty\imgui\imgui_draw.cpp">
<Filter>imgui</Filter>
</ClCompile>
<ClCompile Include="..\thirdparty\imgui\imgui_impl_glfw.cpp">
<Filter>imgui</Filter>
</ClCompile>
<ClCompile Include="..\thirdparty\imgui\imgui_impl_opengl3.cpp">
<Filter>imgui</Filter>
</ClCompile>
<ClCompile Include="..\thirdparty\imgui\imgui_widgets.cpp">
<Filter>imgui</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\Camera.h">
Expand Down Expand Up @@ -101,6 +119,30 @@
<ClInclude Include="src\hdrloader.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\thirdparty\imgui\imconfig.h">
<Filter>imgui</Filter>
</ClInclude>
<ClInclude Include="..\thirdparty\imgui\imgui.h">
<Filter>imgui</Filter>
</ClInclude>
<ClInclude Include="..\thirdparty\imgui\imgui_impl_glfw.h">
<Filter>imgui</Filter>
</ClInclude>
<ClInclude Include="..\thirdparty\imgui\imgui_impl_opengl3.h">
<Filter>imgui</Filter>
</ClInclude>
<ClInclude Include="..\thirdparty\imgui\imgui_internal.h">
<Filter>imgui</Filter>
</ClInclude>
<ClInclude Include="..\thirdparty\imgui\imstb_rectpack.h">
<Filter>imgui</Filter>
</ClInclude>
<ClInclude Include="..\thirdparty\imgui\imstb_textedit.h">
<Filter>imgui</Filter>
</ClInclude>
<ClInclude Include="..\thirdparty\imgui\imstb_truetype.h">
<Filter>imgui</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="src\shaders\Tiled\AccumFrag.glsl">
Expand Down
74 changes: 72 additions & 2 deletions PathTracer/src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@
#include "TiledRenderer.h"
#include "ProgressiveRenderer.h"
#include "Camera.h"
#include "imgui.h"
#include "imgui_impl_glfw.h"
#include "imgui_impl_opengl3.h"

static void glfw_error_callback(int error, const char* description)
{
fprintf(stderr, "Glfw Error %d: %s\n", error, description);
}


using namespace glm;
using namespace std;
Expand All @@ -28,7 +37,7 @@ Renderer *renderer;

void initScene()
{
scene = LoadScene("./assets/ajax.scene");
scene = LoadScene("./assets/cornell.scene");

if (!scene)
{
Expand Down Expand Up @@ -94,6 +103,11 @@ void render(GLFWwindow *window)
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glViewport(0, 0, screenSize.x, screenSize.y);
renderer->present();

// Rendering
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());

glfwSwapBuffers(window);
}

Expand Down Expand Up @@ -148,24 +162,80 @@ void main()
glfwSwapInterval(0);
glewInit();

// Setup Dear ImGui context
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO(); (void)io;
//io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
//io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls

// Setup Dear ImGui style
ImGui::StyleColorsDark();
//ImGui::StyleColorsClassic();

#if __APPLE__
// GL 3.2 + GLSL 150
const char* glsl_version = "#version 150";
/*glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // 3.2+ only
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // Required on Mac
*/
#else
// GL 3.0 + GLSL 130
const char* glsl_version = "#version 130";
//glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
//glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
//glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // 3.2+ only
//glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // 3.0+ only
#endif

// Setup Platform/Renderer bindings
ImGui_ImplGlfw_InitForOpenGL(window, true);
ImGui_ImplOpenGL3_Init(glsl_version);

if (!initRenderer())
return;

double lastTime = glfwGetTime();
while (!glfwWindowShouldClose(window))
{
glfwPollEvents();

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

{
static float f = 0.0f;
static int counter = 0;

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

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

ImGui::End();
}


if (glfwGetKey(window, GLFW_KEY_ESCAPE))
glfwSetWindowShouldClose(window, GL_TRUE);
double presentTime = glfwGetTime();
update((float)(presentTime - lastTime), window);
lastTime = presentTime;

render(window);
}

delete renderer;
delete scene;

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

glfwTerminate();
}

75 changes: 75 additions & 0 deletions thirdparty/imgui/imconfig.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
//-----------------------------------------------------------------------------
// COMPILE-TIME OPTIONS FOR DEAR IMGUI
// Runtime options (clipboard callbacks, enabling various features, etc.) can generally be set via the ImGuiIO structure.
// You can use ImGui::SetAllocatorFunctions() before calling ImGui::CreateContext() to rewire memory allocation functions.
//-----------------------------------------------------------------------------
// A) You may edit imconfig.h (and not overwrite it when updating imgui, or maintain a patch/branch with your modifications to imconfig.h)
// B) or add configuration directives in your own file and compile with #define IMGUI_USER_CONFIG "myfilename.h"
// If you do so you need to make sure that configuration settings are defined consistently _everywhere_ dear imgui is used, which include
// the imgui*.cpp files but also _any_ of your code that uses imgui. This is because some compile-time options have an affect on data structures.
// Defining those options in imconfig.h will ensure every compilation unit gets to see the same data structure layouts.
// Call IMGUI_CHECKVERSION() from your .cpp files to verify that the data structures your files are using are matching the ones imgui.cpp is using.
//-----------------------------------------------------------------------------

#pragma once

//---- Define assertion handler. Defaults to calling assert().
//#define IM_ASSERT(_EXPR) MyAssert(_EXPR)
//#define IM_ASSERT(_EXPR) ((void)(_EXPR)) // Disable asserts

//---- Define attributes of all API symbols declarations, e.g. for DLL under Windows.
//#define IMGUI_API __declspec( dllexport )
//#define IMGUI_API __declspec( dllimport )

//---- Don't define obsolete functions/enums names. Consider enabling from time to time after updating to avoid using soon-to-be obsolete function/names.
//#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS

//---- Don't implement demo windows functionality (ShowDemoWindow()/ShowStyleEditor()/ShowUserGuide() methods will be empty)
//---- It is very strongly recommended to NOT disable the demo windows during development. Please read the comments in imgui_demo.cpp.
//#define IMGUI_DISABLE_DEMO_WINDOWS

//---- Don't implement some functions to reduce linkage requirements.
//#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS // [Win32] Don't implement default clipboard handler. Won't use and link with OpenClipboard/GetClipboardData/CloseClipboard etc.
//#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] Don't implement default IME handler. Won't use and link with ImmGetContext/ImmSetCompositionWindow.
//#define IMGUI_DISABLE_WIN32_FUNCTIONS // [Win32] Won't use and link with any Win32 function.
//#define IMGUI_DISABLE_FORMAT_STRING_FUNCTIONS // Don't implement ImFormatString/ImFormatStringV so you can implement them yourself if you don't want to link with vsnprintf.
//#define IMGUI_DISABLE_MATH_FUNCTIONS // Don't implement ImFabs/ImSqrt/ImPow/ImFmod/ImCos/ImSin/ImAcos/ImAtan2 wrapper so you can implement them yourself. Declare your prototypes in imconfig.h.
//#define IMGUI_DISABLE_DEFAULT_ALLOCATORS // Don't implement default allocators calling malloc()/free() to avoid linking with them. You will need to call ImGui::SetAllocatorFunctions().

//---- Include imgui_user.h at the end of imgui.h as a convenience
//#define IMGUI_INCLUDE_IMGUI_USER_H

//---- Pack colors to BGRA8 instead of RGBA8 (to avoid converting from one to another)
//#define IMGUI_USE_BGRA_PACKED_COLOR

//---- Avoid multiple STB libraries implementations, or redefine path/filenames to prioritize another version
// By default the embedded implementations are declared static and not available outside of imgui cpp files.
//#define IMGUI_STB_TRUETYPE_FILENAME "my_folder/stb_truetype.h"
//#define IMGUI_STB_RECT_PACK_FILENAME "my_folder/stb_rect_pack.h"
//#define IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION
//#define IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION

//---- Define constructor and implicit cast operators to convert back<>forth between your math types and ImVec2/ImVec4.
// This will be inlined as part of ImVec2 and ImVec4 class declarations.
/*
#define IM_VEC2_CLASS_EXTRA \
ImVec2(const MyVec2& f) { x = f.x; y = f.y; } \
operator MyVec2() const { return MyVec2(x,y); }
#define IM_VEC4_CLASS_EXTRA \
ImVec4(const MyVec4& f) { x = f.x; y = f.y; z = f.z; w = f.w; } \
operator MyVec4() const { return MyVec4(x,y,z,w); }
*/

//---- Use 32-bit vertex indices (default is 16-bit) to allow meshes with more than 64K vertices. Render function needs to support it.
//#define ImDrawIdx unsigned int

//---- Tip: You can add extra functions within the ImGui:: namespace, here or in your own headers files.
/*
namespace ImGui
{
void MyFunction(const char* name, const MyMatrix44& v);
}
*/
#define IMGUI_IMPL_OPENGL_LOADER_GLEW
#define GLFW_EXPOSE_NATIVE_WGL
Loading

0 comments on commit 8e3d465

Please sign in to comment.