23#include <imgui_impl_sdl2.h>
24#include <imgui_impl_opengl3.h>
29jevois::ImGuiBackendSDL::ImGuiBackendSDL() :
30 jevois::ImGuiBackend(), itsSDLctx(0), itsSDLwin(nullptr)
34jevois::ImGuiBackendSDL::~ImGuiBackendSDL()
36 ImGui_ImplOpenGL3_Shutdown();
37 ImGui_ImplSDL2_Shutdown();
38 ImGui::DestroyContext();
40 if (itsSDLwin) SDL_DestroyWindow(itsSDLwin);
41 if (itsSDLctx) SDL_GL_DeleteContext(itsSDLctx);
46void jevois::ImGuiBackendSDL::init(
unsigned short,
unsigned short,
bool)
50void jevois::ImGuiBackendSDL::init(
unsigned short w,
unsigned short h,
bool fullscreen,
float scale,
bool)
52 if (itsSDLwin) {
LERROR(
"Already initialized -- IGNORED");
return; }
55 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER))
56 LFATAL(
"SDL initialization error: " << SDL_GetError());
59 SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
60 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
61 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
64 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
68 SDL_WindowFlags window_flags;
69 if (fullscreen) window_flags = (SDL_WindowFlags)(SDL_WINDOW_OPENGL|SDL_WINDOW_FULLSCREEN | SDL_WINDOW_ALLOW_HIGHDPI);
70 else window_flags = (SDL_WindowFlags)(SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);
71 itsSDLwin = SDL_CreateWindow(
"JeVois-Pro", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, w,
h, window_flags);
72 itsSDLctx = SDL_GL_CreateContext(itsSDLwin);
73 SDL_GL_MakeCurrent(itsSDLwin, itsSDLctx);
74 SDL_GL_SetSwapInterval(1);
78 ImGui::CreateContext();
79 ImGuiIO & io = ImGui::GetIO();
80 io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
81 io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad;
84 ImGui::StyleColorsDark();
85 io.FontGlobalScale = scale;
86 ImGui::GetStyle().ScaleAllSizes(scale);
89 ImGui_ImplSDL2_InitForOpenGL(itsSDLwin, itsSDLctx);
90 ImGui_ImplOpenGL3_Init(
"#version 300 es");
108 LINFO(glGetString(GL_VERSION) <<
' '<< glGetString(GL_VENDOR) <<
" (" << glGetString(GL_RENDERER) <<
')');
112 io.ConfigDebugHighlightIdConflicts =
false;
116bool jevois::ImGuiBackendSDL::pollEvents(
bool & shouldclose)
120 while (SDL_PollEvent(&event))
123 ImGui_ImplSDL2_ProcessEvent(&event);
124 if (event.type == SDL_QUIT) shouldclose =
true;
125 if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE &&
126 event.window.windowID == SDL_GetWindowID(itsSDLwin)) shouldclose =
true;
135void jevois::ImGuiBackendSDL::newFrame()
137 glClear(GL_COLOR_BUFFER_BIT);
138 ImGui_ImplOpenGL3_NewFrame();
139 ImGui_ImplSDL2_NewFrame();
144void jevois::ImGuiBackendSDL::render()
147 ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
148 SDL_GL_SwapWindow(itsSDLwin);
152void jevois::ImGuiBackendSDL::getWindowSize(
unsigned short & w,
unsigned short &
h)
const
157 SDL_GetWindowSize(itsSDLwin, &ww, &hh);
#define LFATAL(msg)
Convenience macro for users to print out console or syslog messages, FATAL level.
#define LERROR(msg)
Convenience macro for users to print out console or syslog messages, ERROR level.
#define LINFO(msg)
Convenience macro for users to print out console or syslog messages, INFO level.
Main namespace for all JeVois classes and functions.