67 lines
2.3 KiB
C++
67 lines
2.3 KiB
C++
#include <iostream>
|
|
|
|
// imgui includes
|
|
#include <imgui/imgui.h>
|
|
#include <imgui/backends/imgui_impl_sdl2.h>
|
|
#include <imgui/backends/imgui_impl_opengl3.h>
|
|
#include <SDL2/SDL.h>
|
|
#if defined(IMGUI_IMPL_OPENGL_ES2)
|
|
#include <SDL2/SDL_opengles2.h>
|
|
#else
|
|
#include <SDL2/SDL_opengl.h>
|
|
#endif
|
|
|
|
|
|
int
|
|
main()
|
|
{
|
|
// Should this use the SDL_EVENTS subsystem?
|
|
if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER) != 0) {
|
|
std::cerr << "kge: failed to initialize SDL" << std::endl;
|
|
std::cerr << "\t" << SDL_GetError() << std::endl;
|
|
return -1;
|
|
}
|
|
|
|
// Decide GL+GLSL versions. Taken from the imgui examples.
|
|
#if defined(IMGUI_IMPL_OPENGL_ES2)
|
|
// GL ES 2.0 + GLSL 100
|
|
const char* glsl_version = "#version 100";
|
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, 0);
|
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
|
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
|
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
|
|
#elif defined(__APPLE__)
|
|
// GL 3.2 Core + GLSL 150
|
|
const char* glsl_version = "#version 150";
|
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG); // Always required on Mac
|
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
|
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
|
|
#else
|
|
// GL 3.0 + GLSL 130
|
|
const char* glsl_version = "#version 130";
|
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, 0);
|
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
|
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
|
|
#endif
|
|
|
|
// From 2.0.18: Enable native IME.
|
|
#ifdef SDL_HINT_IME_SHOW_UI
|
|
SDL_SetHint(SDL_HINT_IME_SHOW_UI, "1");
|
|
#endif
|
|
|
|
// Create window with graphics context
|
|
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
|
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
|
|
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
|
|
SDL_WindowFlags window_flags = (SDL_WindowFlags)(SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);
|
|
SDL_Window* window = SDL_CreateWindow("Dear ImGui SDL2+OpenGL3 example", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, window_flags);
|
|
SDL_GLContext gl_context = SDL_GL_CreateContext(window);
|
|
SDL_GL_MakeCurrent(window, gl_context);
|
|
SDL_GL_SetSwapInterval(1); // Enable vsync
|
|
|
|
return 0;
|
|
}
|
|
|