Skip to content

Commit 486d780

Browse files
committed
Fixes after imgui update.
1 parent 308153c commit 486d780

File tree

8 files changed

+60
-28
lines changed

8 files changed

+60
-28
lines changed

sources/app/CEngine.cpp

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ void CEngine::initialize()
122122
spdlog::debug("Engine.initialize()");
123123

124124
initializeVideo();
125-
125+
initializeImGui();
126126
initializeInput();
127127

128128
// Resource manager
@@ -180,6 +180,15 @@ void CEngine::initializeVideo()
180180
glEnable(GL_MULTISAMPLE);
181181
}
182182

183+
void CEngine::initializeImGui()
184+
{
185+
IMGUI_CHECKVERSION();
186+
ImGui::CreateContext();
187+
188+
ImGui_ImplSDL2_InitForOpenGL(SDL_GetWindowFromID(mMainWindow->getId()), nullptr);
189+
ImGui_ImplOpenGL3_Init();
190+
}
191+
183192
void CEngine::initializeInput()
184193
{
185194
spdlog::debug(" - input");
@@ -191,6 +200,7 @@ void CEngine::initializeInput()
191200

192201
void CEngine::run()
193202
{
203+
194204
spdlog::set_level(spdlog::level::debug);
195205

196206
spdlog::info("Engine.run()");
@@ -223,11 +233,10 @@ void CEngine::prepare()
223233
constexpr auto nbEntities = std::size_t(10000);
224234
mEntityManager.reserve(nbEntities);
225235

226-
ImGui_ImplSDL2_InitForOpenGL(SDL_GetWindowFromID(mMainWindow->getId()), nullptr);
227-
228-
ImGuiStyle& style = ImGui::GetStyle();
229-
style.WindowRounding = 0;
230-
style.Colors[ImGuiCol_WindowBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.30f);
236+
ImGui::StyleColorsDark();
237+
// ImGuiStyle& style = ImGui::GetStyle();
238+
// style.WindowRounding = 0;
239+
// style.Colors[ImGuiCol_WindowBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.30f);
231240

232241
m2dRenderSystem.reset(new C2DRenderSystem(mEntityManager));
233242
m3dRenderSystem.reset(new C3DRenderSystem(mEntityManager, *mResourceManager));
@@ -432,7 +441,7 @@ void CEngine::onSwapBuffers()
432441

433442
void CEngine::finalize()
434443
{
435-
ImGui_ImplSDL2_Shutdown();
444+
imgui::shutdown();
436445
}
437446

438447
void CEngine::onEvent()
@@ -487,10 +496,10 @@ void CEngine::onDraw()
487496
const glm::mat4 projection = m_camera->get_projection();
488497

489498
m3dRenderSystem->prepare(m_camera.get());
490-
491499
m3dRenderSystem->render(view, projection);
492500

493-
ImGui_ImplSDL2_NewFrame(SDL_GetWindowFromID(mMainWindow->getId()));
501+
imgui::new_frame();
494502
m2dRenderSystem->render(view, projection);
495503
ImGui::Render();
504+
imgui::draw();
496505
}

sources/app/CEngine.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class CEngine
3434
private:
3535
void initialize();
3636
void initializeVideo();
37+
void initializeImGui(); // should be after initialize video
3738
void initializeInput();
3839

3940
void prepare();

sources/app/auxiliary/imgui.hpp

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,30 @@
11
#pragma once
22

33
#include "imgui.h"
4+
#include "imgui_impl_opengl3.h"
45
#include "imgui_impl_sdl.h"
5-
// #include "imgui/imgui_internal.h"
6+
7+
8+
namespace imgui
9+
{
10+
11+
inline void shutdown()
12+
{
13+
ImGui_ImplOpenGL3_Shutdown();
14+
ImGui_ImplSDL2_Shutdown();
15+
ImGui::DestroyContext();
16+
}
17+
18+
inline void new_frame()
19+
{
20+
ImGui_ImplOpenGL3_NewFrame();
21+
ImGui_ImplSDL2_NewFrame();
22+
ImGui::NewFrame();
23+
}
24+
25+
inline void draw()
26+
{
27+
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
28+
}
29+
30+
} // namespace imgui

sources/app/entities/windows/CEngineDebugWindow.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ void CEngineDebugWindow::draw()
1717
{
1818
ImGui::ShowDemoWindow();
1919

20-
ImGui::Text("App %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate,
21-
ImGui::GetIO().Framerate);
20+
ImGui::Text("App %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
2221

2322
auto mouse = CRegistry::get<glm::ivec2>("mouse/position");
2423

sources/app/entities/windows/CEntityManagerWindow.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -167,19 +167,19 @@ void CEntityManagerWindow::draw()
167167

168168
{
169169
auto range = component.m_particle_emitter->getEmitIntervalRange();
170-
ImGui::SliderFloat2("Emit interval", &range[0], 0.00001f, 2.0f, "%.5f", 3.f);
170+
ImGui::SliderFloat2("Emit interval", &range[0], 0.00001f, 2.0f, "%.5f", 1.f);
171171
component.m_particle_emitter->setEmitIntervalRange(range.x, range.y);
172172
}
173173

174174
{
175175
auto range = component.m_particle_emitter->getLifetimeRange();
176-
ImGui::SliderFloat2("Lifetime range", &range[0], 0.0001f, 100.0f, "%.4f", 3.f);
176+
ImGui::SliderFloat2("Lifetime range", &range[0], 0.0001f, 100.0f, "%.4f", 1.f);
177177
component.m_particle_emitter->setLifetimeRange(range.x, range.y);
178178
}
179179

180180
{
181181
auto range = component.m_particle_emitter->getSpeedRange();
182-
ImGui::SliderFloat2("Speed range", &range[0], -100.f, 100.0f, "%.3f", 3.f);
182+
ImGui::SliderFloat2("Speed range", &range[0], -100.f, 100.0f, "%.3f", 1.f);
183183
component.m_particle_emitter->setSpeedRange(range.x, range.y);
184184
}
185185

@@ -213,7 +213,7 @@ void CEntityManagerWindow::draw()
213213

214214
{
215215
auto nearAndFar = camera->get_near_far();
216-
ImGui::SliderFloat2("Near / Far", &nearAndFar[0], 0.0001f, 10000.0f, "%.5f", 3.f);
216+
ImGui::SliderFloat2("Near / Far", &nearAndFar[0], 0.0001f, 10000.0f, "%.5f", 1.f);
217217
camera->set_near_far(nearAndFar);
218218
}
219219
}
@@ -228,8 +228,8 @@ void CEntityManagerWindow::draw()
228228
auto light = component.getLight();
229229

230230
ImGui::InputFloat3("Position", &light->mPosition[0]);
231-
ImGui::ColorEdit3("Color", &light->mColor[0], ImGuiColorEditFlags_Float);
232-
ImGui::SliderFloat("Strength", &light->mStrength, 0.0f, 65536.0f, "%.4f", 3.f);
231+
// ImGui::ColorEdit3("Color", &light->mColor[0], ImGuiColorEditFlags_Float);
232+
ImGui::SliderFloat("Strength", &light->mStrength, 0.0f, 65536.0f, "%.4f", 1.f);
233233
}
234234
}
235235

@@ -321,11 +321,11 @@ void CEntityManagerWindow::draw()
321321
material->setEmissiveFactor(emissive);
322322
}
323323

324-
auto baseColor = material->getBaseColorFactor();
325-
if (ImGui::ColorEdit4("Base color", &(baseColor[0]), ImGuiColorEditFlags_Float))
326-
{
327-
material->setBaseColorFactor(baseColor);
328-
}
324+
// auto baseColor = material->getBaseColorFactor();
325+
// if (ImGui::ColorEdit4("Base color", &(baseColor[0]), ImGuiColorEditFlags_Float))
326+
// {
327+
// material->setBaseColorFactor(baseColor);
328+
// }
329329

330330
if (auto tex = material->getBaseColorTexture())
331331
{

sources/app/entities/windows/CShaderManagerWindow.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ void CShaderManagerWindow::draw()
4040
}
4141

4242
ImGui::Begin("Shader manager");
43-
ImGui::ListBox("", &currentProgrmName, vector_getter, static_cast<void*>(&programsNames),
44-
programsNames.size(), 6);
43+
ImGui::ListBox("", &currentProgrmName, vector_getter, static_cast<void*>(&programsNames), programsNames.size(), 6);
4544

4645
if (ImGui::Button("Reload"))
4746
{

sources/app/entities/windows/CTextureManagerWindow.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ void CTextureManagerWindow::draw()
4444
}
4545

4646
ImGui::Begin("Textures manager");
47-
ImGui::ListBox("", &currentProgrmName, vector_getter, static_cast<void*>(&texturesNames),
48-
texturesNames.size(), 6);
47+
ImGui::ListBox("", &currentProgrmName, vector_getter, static_cast<void*>(&texturesNames), texturesNames.size(), 6);
4948
if (numTextures > currentProgrmName)
5049
{
5150
auto tex = textures.at(texturesIds[currentProgrmName]);

vcpkg.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
{
77
"name": "imgui",
88
"default-features": false,
9-
"features": [ "sdl2-binding" ]
9+
"features": [ "sdl2-binding", "opengl3-binding" ]
1010
},
1111
"imguizmo",
1212
"fmt",

0 commit comments

Comments
 (0)