|
|
@ -19,15 +19,17 @@
|
|
|
|
#include <SDL2/SDL.h>
|
|
|
|
#include <SDL2/SDL.h>
|
|
|
|
#include <SDL2/SDL_opengl.h>
|
|
|
|
#include <SDL2/SDL_opengl.h>
|
|
|
|
|
|
|
|
|
|
|
|
ImFont *fontSans = nullptr;
|
|
|
|
bool guiInitialize();
|
|
|
|
ImFont *fontMono = nullptr;
|
|
|
|
void guiRender();
|
|
|
|
static ImGuiIO *io = nullptr;
|
|
|
|
bool guiHandleEvents();
|
|
|
|
|
|
|
|
void guiShutdown();
|
|
|
|
|
|
|
|
|
|
|
|
static SDL_Window *window = nullptr;
|
|
|
|
static SDL_Window *window = nullptr;
|
|
|
|
static decltype(SDL_GL_CreateContext(nullptr)) gl_context;
|
|
|
|
static SDL_GLContext gl_context;
|
|
|
|
|
|
|
|
|
|
|
|
bool guiInitialize()
|
|
|
|
bool guiInitialize()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (SDL_Init(/*SDL_INIT_VIDEO*/0) != 0) {
|
|
|
|
if (SDL_Init(0) != 0) {
|
|
|
|
printf("Error: %s\n", SDL_GetError());
|
|
|
|
printf("Error: %s\n", SDL_GetError());
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -42,6 +44,12 @@ bool guiInitialize()
|
|
|
|
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
|
|
|
|
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
|
|
|
|
WINDOW_WIDTH, WINDOW_HEIGHT,
|
|
|
|
WINDOW_WIDTH, WINDOW_HEIGHT,
|
|
|
|
SDL_WINDOW_OPENGL /*| SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI*/);
|
|
|
|
SDL_WINDOW_OPENGL /*| SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI*/);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (window == nullptr) {
|
|
|
|
|
|
|
|
puts("Error: Could not create the window!");
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
gl_context = SDL_GL_CreateContext(window);
|
|
|
|
gl_context = SDL_GL_CreateContext(window);
|
|
|
|
SDL_GL_MakeCurrent(window, gl_context);
|
|
|
|
SDL_GL_MakeCurrent(window, gl_context);
|
|
|
|
SDL_GL_SetSwapInterval(1); // Enable vsync
|
|
|
|
SDL_GL_SetSwapInterval(1); // Enable vsync
|
|
|
@ -49,10 +57,7 @@ bool guiInitialize()
|
|
|
|
// Setup Dear ImGui context
|
|
|
|
// Setup Dear ImGui context
|
|
|
|
IMGUI_CHECKVERSION();
|
|
|
|
IMGUI_CHECKVERSION();
|
|
|
|
ImGui::CreateContext();
|
|
|
|
ImGui::CreateContext();
|
|
|
|
io = &ImGui::GetIO();
|
|
|
|
|
|
|
|
//io->ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
|
|
|
|
//io->ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
|
|
|
|
fontSans = io->Fonts->AddFontFromFileTTF("fonts/Roboto-Regular.ttf", 20);
|
|
|
|
|
|
|
|
fontMono = io->Fonts->AddFontFromFileTTF("fonts/RobotoMono-Regular.ttf", 20);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ImGui_ImplSDL2_InitForOpenGL(window, gl_context);
|
|
|
|
ImGui_ImplSDL2_InitForOpenGL(window, gl_context);
|
|
|
|
ImGui_ImplOpenGL2_Init();
|
|
|
|
ImGui_ImplOpenGL2_Init();
|
|
|
@ -99,12 +104,18 @@ bool guiInitialize()
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void guiRender(void (*func)())
|
|
|
|
void guiRender()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
glViewport(0, 0, (int)io->DisplaySize.x, (int)io->DisplaySize.y);
|
|
|
|
ImGui::Render();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const auto& displaySize = ImGui::GetIO().DisplaySize;
|
|
|
|
|
|
|
|
const int sizeX = static_cast<int>(displaySize.x);
|
|
|
|
|
|
|
|
const int sizeY = static_cast<int>(displaySize.y);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glViewport(0, 0, sizeX, sizeY);
|
|
|
|
glClearColor(1, 1, 1, 1);
|
|
|
|
glClearColor(1, 1, 1, 1);
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
func();
|
|
|
|
ImGui_ImplOpenGL2_RenderDrawData(ImGui::GetDrawData());
|
|
|
|
SDL_GL_SwapWindow(window);
|
|
|
|
SDL_GL_SwapWindow(window);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -114,11 +125,15 @@ bool guiHandleEvents()
|
|
|
|
|
|
|
|
|
|
|
|
for (SDL_Event event; SDL_PollEvent(&event);) {
|
|
|
|
for (SDL_Event event; SDL_PollEvent(&event);) {
|
|
|
|
ImGui_ImplSDL2_ProcessEvent(&event);
|
|
|
|
ImGui_ImplSDL2_ProcessEvent(&event);
|
|
|
|
if (event.type == SDL_QUIT)
|
|
|
|
if (event.type == SDL_QUIT) {
|
|
|
|
done = true;
|
|
|
|
done = true;
|
|
|
|
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE && event.window.windowID == SDL_GetWindowID(window))
|
|
|
|
} else if (event.type == SDL_WINDOWEVENT) {
|
|
|
|
|
|
|
|
const auto& ew = event.window;
|
|
|
|
|
|
|
|
const auto wid = SDL_GetWindowID(window);
|
|
|
|
|
|
|
|
if (ew.event == SDL_WINDOWEVENT_CLOSE && ew.windowID == wid)
|
|
|
|
done = true;
|
|
|
|
done = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return done;
|
|
|
|
return done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|