Skip to content

Commit 53648d1

Browse files
committed
Cleanup. / Make code work with clang and GLFW.
1 parent 3d65679 commit 53648d1

File tree

19 files changed

+7825
-134
lines changed

19 files changed

+7825
-134
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.vs
22
.build
3+
.DS_Store
34
bin
45
*.VC.db
56
*.VC.opendb

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON)
66
set(CMAKE_CXX_STANDARD 17)
77
set(CMAKE_CXX_STANDARD_REQUIRED YES)
88

9-
if (DEFINED MSVC_VERSION AND (NOT (${MSVC_VERSION} LESS 1400)))
9+
if (DEFINED MSVC_VERSION AND (NOT (MSVC_VERSION LESS 1400)))
1010
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++17")# /permissive-")
1111
endif()
1212

Examples/01-Blueprints/Blueprints.cpp

+28-29
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "application.h"
1+
#include "Application.h"
22
#include <string>
33
#include <vector>
44
#include <map>
@@ -14,7 +14,6 @@ namespace ed = ax::NodeEditor;
1414
namespace util = ax::NodeEditor::Utilities;
1515

1616
using namespace ax;
17-
using namespace ax::ImGuiInterop;
1817

1918
using ax::Widgets::IconType;
2019

@@ -112,7 +111,7 @@ static const int s_PinIconSize = 24;
112111
static std::vector<Node> s_Nodes;
113112
static std::vector<Link> s_Links;
114113
static ImTextureID s_HeaderBackground = nullptr;
115-
static ImTextureID s_SampleImage = nullptr;
114+
//static ImTextureID s_SampleImage = nullptr;
116115
static ImTextureID s_SaveIcon = nullptr;
117116
static ImTextureID s_RestoreIcon = nullptr;
118117

@@ -206,21 +205,21 @@ static bool CanCreateLink(Pin* a, Pin* b)
206205
return true;
207206
}
208207

209-
static void DrawItemRect(ImColor color, float expand = 0.0f)
210-
{
211-
ImGui::GetWindowDrawList()->AddRect(
212-
ImGui::GetItemRectMin() - ImVec2(expand, expand),
213-
ImGui::GetItemRectMax() + ImVec2(expand, expand),
214-
color);
215-
};
208+
//static void DrawItemRect(ImColor color, float expand = 0.0f)
209+
//{
210+
// ImGui::GetWindowDrawList()->AddRect(
211+
// ImGui::GetItemRectMin() - ImVec2(expand, expand),
212+
// ImGui::GetItemRectMax() + ImVec2(expand, expand),
213+
// color);
214+
//};
216215

217-
static void FillItemRect(ImColor color, float expand = 0.0f, float rounding = 0.0f)
218-
{
219-
ImGui::GetWindowDrawList()->AddRectFilled(
220-
ImGui::GetItemRectMin() - ImVec2(expand, expand),
221-
ImGui::GetItemRectMax() + ImVec2(expand, expand),
222-
color, rounding);
223-
};
216+
//static void FillItemRect(ImColor color, float expand = 0.0f, float rounding = 0.0f)
217+
//{
218+
// ImGui::GetWindowDrawList()->AddRectFilled(
219+
// ImGui::GetItemRectMin() - ImVec2(expand, expand),
220+
// ImGui::GetItemRectMax() + ImVec2(expand, expand),
221+
// color, rounding);
222+
//};
224223

225224
static void BuildNode(Node* node)
226225
{
@@ -456,7 +455,7 @@ void Application_Initialize()
456455
s_RestoreIcon = Application_LoadTexture("Data/ic_restore_white_24dp.png");
457456

458457

459-
auto& io = ImGui::GetIO();
458+
//auto& io = ImGui::GetIO();
460459
}
461460

462461
void Application_Finalize()
@@ -805,7 +804,7 @@ void Application_Frame()
805804

806805
ed::SetCurrentEditor(m_Editor);
807806

808-
auto& style = ImGui::GetStyle();
807+
//auto& style = ImGui::GetStyle();
809808

810809
static int contextId = 0;
811810
static bool createNewNode = false;
@@ -1049,16 +1048,16 @@ void Application_Frame()
10491048

10501049
auto drawList = ed::GetNodeBackgroundDrawList(node.ID);
10511050

1052-
const auto fringeScale = ImGui::GetStyle().AntiAliasFringeScale;
1053-
const auto unitSize = 1.0f / fringeScale;
1051+
//const auto fringeScale = ImGui::GetStyle().AntiAliasFringeScale;
1052+
//const auto unitSize = 1.0f / fringeScale;
10541053

1055-
const auto ImDrawList_AddRect = [](ImDrawList* drawList, const ImVec2& a, const ImVec2& b, ImU32 col, float rounding, int rounding_corners, float thickness)
1056-
{
1057-
if ((col >> 24) == 0)
1058-
return;
1059-
drawList->PathRect(a, b, rounding, rounding_corners);
1060-
drawList->PathStroke(col, true, thickness);
1061-
};
1054+
//const auto ImDrawList_AddRect = [](ImDrawList* drawList, const ImVec2& a, const ImVec2& b, ImU32 col, float rounding, int rounding_corners, float thickness)
1055+
//{
1056+
// if ((col >> 24) == 0)
1057+
// return;
1058+
// drawList->PathRect(a, b, rounding, rounding_corners);
1059+
// drawList->PathStroke(col, true, thickness);
1060+
//};
10621061

10631062
drawList->AddRectFilled(to_imvec(inputsRect.top_left()) + ImVec2(0, 1), to_imvec(inputsRect.bottom_right()),
10641063
IM_COL32((int)(255 * pinBackground.x), (int)(255 * pinBackground.y), (int)(255 * pinBackground.z), inputAlpha), 4.0f, 12);
@@ -1111,7 +1110,7 @@ void Application_Frame()
11111110
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, commentAlpha * ImGui::GetStyle().Alpha);
11121111

11131112
auto min = ed::GetGroupMin();
1114-
auto max = ed::GetGroupMax();
1113+
//auto max = ed::GetGroupMax();
11151114

11161115
ImGui::SetCursorScreenPos(min - ImVec2(-8, ImGui::GetTextLineHeightWithSpacing() + 4));
11171116
ImGui::BeginGroup();

Examples/Common/Application/CMakeLists.txt

+20
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ if (WIN32)
99
Source/DX11/imgui_impl_dx11.cpp
1010
Source/DX11/imgui_impl_dx11.h
1111
)
12+
else()
13+
find_package(glfw3 3.2 REQUIRED)
14+
find_package(OpenGL REQUIRED)
15+
16+
list(APPEND _Application_Sources
17+
Source/GLFW/Entry.cpp
18+
Source/GLFW/imgui_impl_glfw_gl3.cpp
19+
Source/GLFW/imgui_impl_glfw_gl3.h
20+
)
1221
endif()
1322

1423

@@ -41,6 +50,17 @@ if (WIN32)
4150
)
4251

4352
target_link_libraries(Application PRIVATE ImGui NodeEditor Shared d3d11.lib d3dcompiler.lib d3dx11)
53+
else()
54+
add_subdirectory(${CMAKE_SOURCE_DIR}/ThirdParty/gl3w ${CMAKE_BINARY_DIR}/ThirdParty/gl3w)
55+
56+
target_include_directories(Application PRIVATE ${OPENGL_INCLUDE_DIR})
57+
target_link_libraries(Application PRIVATE ${OPENGL_gl_LIBRARY} gl3w glfw)
58+
59+
if (APPLE)
60+
target_link_libraries(Application PRIVATE
61+
"-framework CoreFoundation"
62+
)
63+
endif()
4464
endif()
4565

4666
set_property(TARGET Application PROPERTY FOLDER "Examples/Common")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
// ImGui - standalone example application for GLFW + OpenGL 3, using programmable pipeline
2+
// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp.
3+
// (GLFW is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.)
4+
// (GL3W is a helper library to access OpenGL functions since there is no standard header to access modern OpenGL functions easily. Alternatives are GLEW, Glad, etc.)
5+
6+
#include <imgui.h>
7+
#include "imgui_impl_glfw_gl3.h"
8+
#include <stdio.h>
9+
#include <GL/gl3w.h> // This example is using gl3w to access OpenGL functions (because it is small). You may use glew/glad/glLoadGen/etc. whatever already works for you.
10+
#include <GLFW/glfw3.h>
11+
#include "Application.h"
12+
13+
static void error_callback(int error, const char* description)
14+
{
15+
fprintf(stderr, "Error %d: %s\n", error, description);
16+
}
17+
18+
ImTextureID Application_LoadTexture(const char* path)
19+
{
20+
return nullptr;
21+
}
22+
23+
ImTextureID Application_CreateTexture(const void* data, int width, int height)
24+
{
25+
return nullptr;
26+
}
27+
28+
void Application_DestroyTexture(ImTextureID texture)
29+
{
30+
}
31+
32+
int Application_GetTextureWidth(ImTextureID texture)
33+
{
34+
return 0;
35+
}
36+
37+
int Application_GetTextureHeight(ImTextureID texture)
38+
{
39+
return 0;
40+
}
41+
42+
int main(int, char**)
43+
{
44+
// Setup window
45+
glfwSetErrorCallback(error_callback);
46+
if (!glfwInit())
47+
return 1;
48+
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
49+
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
50+
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
51+
#if __APPLE__
52+
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
53+
#endif
54+
GLFWwindow* window = glfwCreateWindow(1280, 720, "ImGui OpenGL3 example", NULL, NULL);
55+
glfwMakeContextCurrent(window);
56+
glfwSwapInterval(1); // Enable vsync
57+
gl3wInit();
58+
59+
// Setup ImGui binding
60+
ImGui_ImplGlfwGL3_Init(window, true);
61+
62+
// Load Fonts
63+
// - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them.
64+
// - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple.
65+
// - If the file cannot be loaded, the function will return NULL. Please handle those errors in your application (e.g. use an assertion, or display an error and quit).
66+
// - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call.
67+
// - Read 'extra_fonts/README.txt' for more instructions and details.
68+
// - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ !
69+
ImGuiIO& io = ImGui::GetIO();
70+
//io.Fonts->AddFontDefault();
71+
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/Roboto-Medium.ttf", 16.0f);
72+
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/Cousine-Regular.ttf", 15.0f);
73+
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 16.0f);
74+
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f);
75+
//ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
76+
//IM_ASSERT(font != NULL);
77+
78+
io.MouseDrawCursor = true;
79+
80+
ImVec4 clear_color = ImVec4(0.125f, 0.125f, 0.125f, 1.00f);
81+
82+
Application_Initialize();
83+
84+
// Main loop
85+
while (!glfwWindowShouldClose(window))
86+
{
87+
// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.
88+
// - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application.
89+
// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application.
90+
// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
91+
glfwPollEvents();
92+
ImGui_ImplGlfwGL3_NewFrame();
93+
94+
ImGui::SetNextWindowPos(ImVec2(0, 0));
95+
ImGui::SetNextWindowSize(io.DisplaySize);
96+
ImGui::Begin("Content", nullptr, ImVec2(0, 0), 0.0f,
97+
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove |
98+
ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse | ImGuiWindowFlags_NoSavedSettings |
99+
ImGuiWindowFlags_NoBringToFrontOnFocus);
100+
101+
Application_Frame();
102+
103+
ImGui::End();
104+
105+
// Rendering
106+
int display_w, display_h;
107+
glfwGetFramebufferSize(window, &display_w, &display_h);
108+
glViewport(0, 0, display_w, display_h);
109+
glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w);
110+
glClear(GL_COLOR_BUFFER_BIT);
111+
ImGui::Render();
112+
glfwSwapBuffers(window);
113+
}
114+
115+
Application_Finalize();
116+
117+
// Cleanup
118+
ImGui_ImplGlfwGL3_Shutdown();
119+
glfwTerminate();
120+
121+
return 0;
122+
}

0 commit comments

Comments
 (0)