Skip to content

Instantly share code, notes, and snippets.

@soufianekhiat
Created May 26, 2024 20:00
Show Gist options
  • Save soufianekhiat/66abf7f4c4ccee3645d6ae5d4642f8af to your computer and use it in GitHub Desktop.
Save soufianekhiat/66abf7f4c4ccee3645d6ae5d4642f8af to your computer and use it in GitHub Desktop.
#include <imgui.h>
// It will include ImPlatform.cpp internally
#define IM_PLATFORM_IMPLEMENTATION
// Define target
//#define IM_CURRENT_TARGET IM_TARGET_WIN32_DX11
// Or
//#define IM_CURRENT_TARGET (IM_PLATFORM_WIN32 | IM_GFX_OPENGL3)
// Or a permutation
// sidenote: Not all permutations are valid for instance:
// __DEAR_MAC__ + __DEAR_GFX_DX11__ // Which is really sad
#define __DEAR_WIN__
#define __DEAR_GFX_DX11__
#include <ImPlatform.h>
int main()
{
if ( !ImPlatform::ImInit( "ImPlatform Demo", 1024, 764 ) )
return 1;
// Setup Dear ImGui context
ImGuiIO& io = ImGui::GetIO(); ( void )io;
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad;
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable;
// Setup Dear ImGui style
ImGui::StyleColorsDark();
//ImGui::StyleColorsClassic();
//io.Fonts->AddFontFromFileTTF( "../extern/FiraCode/distr/ttf/FiraCode-Medium.ttf", 16.0f );
// When viewports are enabled we tweak WindowRounding/WindowBg so platform windows can look identical to regular ones.
ImGuiStyle& style = ImGui::GetStyle();
if ( io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable )
{
style.WindowRounding = 0.0f;
style.Colors[ ImGuiCol_WindowBg ].w = 1.0f;
}
ImPlatform::ImBegin();
ImVec4 clear_color = ImVec4( 0.0f, 0.0f, 0.0f, 1.0f );
while ( ImPlatform::ImPlatformContinue() )
{
bool quit = ImPlatform::ImPlatformEvents();
if ( quit )
break;
if ( !ImPlatform::ImBeginFrame() )
{
continue;
}
// ImGui Code
bool show = true;
ImGui::ShowDemoWindow( &show );
ImPlatform::ImEndFrame( clear_color );
// Update and Render additional Platform Windows
if ( io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable )
{
ImGui::UpdatePlatformWindows();
ImGui::RenderPlatformWindowsDefault();
ImPlatform::ImGfxViewportPost();
}
ImPlatform::ImSwapGfx();
}
ImPlatform::ImEnd();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment