Set C++ standard; code formatting.
On MacOS, clang will default to C++2003 if this isn't explicitly set.
This commit is contained in:
parent
47bba754f4
commit
72e3bf77a7
|
@ -1,6 +1,8 @@
|
|||
cmake_minimum_required(VERSION 3.22)
|
||||
|
||||
project(kge)
|
||||
project(kge LANGUAGES CXX)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
find_package(SDL2 REQUIRED)
|
||||
find_package(OpenGL REQUIRED)
|
||||
|
@ -24,24 +26,21 @@ add_library(imgui STATIC
|
|||
ext/imgui/backends/imgui_impl_opengl3.h
|
||||
|
||||
ext/imgui/misc/freetype/imgui_freetype.cpp
|
||||
ext/imgui/misc/freetype/imgui_freetype.h
|
||||
)
|
||||
ext/imgui/misc/freetype/imgui_freetype.h)
|
||||
add_library(imgui::imgui ALIAS imgui)
|
||||
target_link_libraries(imgui
|
||||
PUBLIC
|
||||
OpenGL::GL
|
||||
$<TARGET_NAME_IF_EXISTS:SDL2::SDL2main>
|
||||
$<IF:$<TARGET_EXISTS:SDL2::SDL2>,SDL2::SDL2,SDL2::SDL2-static>
|
||||
Freetype::Freetype
|
||||
)
|
||||
Freetype::Freetype)
|
||||
target_include_directories(imgui PUBLIC
|
||||
ext/imgui/
|
||||
ext/imgui/backends/
|
||||
ext/imgui/misc/freetype
|
||||
${FREETYPE_INCLUDE_DIRS}
|
||||
)
|
||||
${FREETYPE_INCLUDE_DIRS})
|
||||
|
||||
include_directories(ext/)
|
||||
include_directories(ext/ ${SDL2_INCLUDE_DIRS})
|
||||
|
||||
add_executable(kge
|
||||
kge.cc
|
||||
|
|
76
kge.cc
76
kge.cc
|
@ -5,13 +5,15 @@
|
|||
#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
|
||||
|
||||
#include "fonts/b612_mono.h"
|
||||
#include "fonts/brassmono.h"
|
||||
|
||||
|
||||
|
@ -39,8 +41,10 @@ main()
|
|||
#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_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
|
||||
|
@ -61,8 +65,13 @@ main()
|
|||
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_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
|
||||
|
@ -70,7 +79,8 @@ main()
|
|||
// Setup Dear ImGui context
|
||||
IMGUI_CHECKVERSION();
|
||||
ImGui::CreateContext();
|
||||
ImGuiIO& io = ImGui::GetIO(); (void)io;
|
||||
ImGuiIO &io = ImGui::GetIO();
|
||||
(void) io;
|
||||
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
|
||||
|
||||
// Setup Dear ImGui style
|
||||
|
@ -82,17 +92,9 @@ main()
|
|||
ImGui_ImplOpenGL3_Init(glsl_version);
|
||||
|
||||
for (auto pixelSize: fontPixelSizes) {
|
||||
io.Fonts->AddFontFromMemoryCompressedTTF(BrassMono_Regular_compressed_data, BrassMono_Regular_compressed_size, pixelSize);
|
||||
io.Fonts->AddFontFromMemoryCompressedTTF(B612Mono_Regular_compressed_data, B612Mono_Regular_compressed_size, pixelSize);
|
||||
|
||||
io.Fonts->AddFontFromMemoryCompressedTTF(B612Mono_Bold_compressed_data, B612Mono_Bold_compressed_size, pixelSize);
|
||||
io.Fonts->AddFontFromMemoryCompressedTTF(BrassMono_Bold_compressed_data, BrassMono_Bold_compressed_size, pixelSize);
|
||||
|
||||
io.Fonts->AddFontFromMemoryCompressedTTF(B612Mono_BoldItalic_compressed_data, B612Mono_BoldItalic_compressed_size, pixelSize);
|
||||
io.Fonts->AddFontFromMemoryCompressedTTF(BrassMono_BoldItalic_compressed_data, BrassMono_BoldItalic_compressed_size, pixelSize);
|
||||
|
||||
io.Fonts->AddFontFromMemoryCompressedTTF(B612Mono_Italic_compressed_data, B612Mono_Italic_compressed_size, pixelSize);
|
||||
io.Fonts->AddFontFromMemoryCompressedTTF(BrassMono_Italic_compressed_data, BrassMono_Italic_compressed_size, pixelSize);
|
||||
io.Fonts->AddFontFromMemoryCompressedTTF(
|
||||
BrassMono_Regular_compressed_data,
|
||||
BrassMono_Regular_compressed_size, pixelSize);
|
||||
}
|
||||
|
||||
bool done = false;
|
||||
|
@ -107,12 +109,13 @@ main()
|
|||
// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application, or clear/overwrite your copy of the keyboard data.
|
||||
// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event))
|
||||
{
|
||||
while (SDL_PollEvent(&event)) {
|
||||
ImGui_ImplSDL2_ProcessEvent(&event);
|
||||
if (event.type == SDL_QUIT)
|
||||
done = true;
|
||||
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE && event.window.windowID == SDL_GetWindowID(window))
|
||||
if (event.type == SDL_WINDOWEVENT &&
|
||||
event.window.event == SDL_WINDOWEVENT_CLOSE &&
|
||||
event.window.windowID == SDL_GetWindowID(window))
|
||||
done = true;
|
||||
}
|
||||
|
||||
|
@ -129,27 +132,34 @@ main()
|
|||
static float f = 0.0f;
|
||||
static int counter = 0;
|
||||
|
||||
ImGui::Begin("Hello, world!"); // Create a window called "Hello, world!" and append into it.
|
||||
ImGui::Begin(
|
||||
"Hello, world!"); // Create a window called "Hello, world!" and append into it.
|
||||
|
||||
ImGui::Text("This is some useful text."); // Display some text (you can use a format strings too)
|
||||
ImGui::Checkbox("Demo Window", &show_demo_window); // Edit bools storing our window open/close state
|
||||
ImGui::Text(
|
||||
"This is some useful text."); // Display some text (you can use a format strings too)
|
||||
ImGui::Checkbox("Demo Window",
|
||||
&show_demo_window); // Edit bools storing our window open/close state
|
||||
ImGui::Checkbox("Another Window", &show_another_window);
|
||||
|
||||
ImGui::SliderFloat("float", &f, 0.0f, 1.0f); // Edit 1 float using a slider from 0.0f to 1.0f
|
||||
ImGui::ColorEdit3("clear color", (float*)&clear_color); // Edit 3 floats representing a color
|
||||
ImGui::SliderFloat("float", &f, 0.0f,
|
||||
1.0f); // Edit 1 float using a slider from 0.0f to 1.0f
|
||||
ImGui::ColorEdit3("clear color",
|
||||
(float *) &clear_color); // Edit 3 floats representing a color
|
||||
|
||||
if (ImGui::Button("Button")) // Buttons return true when clicked (most widgets return true when edited/activated)
|
||||
if (ImGui::Button(
|
||||
"Button")) // Buttons return true when clicked (most widgets return true when edited/activated)
|
||||
counter++;
|
||||
ImGui::SameLine();
|
||||
ImGui::Text("counter = %d", counter);
|
||||
|
||||
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / io.Framerate, io.Framerate);
|
||||
ImGui::Text(
|
||||
"Application average %.3f ms/frame (%.1f FPS)",
|
||||
1000.0f / io.Framerate, io.Framerate);
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
// 3. Show another simple window.
|
||||
if (show_another_window)
|
||||
{
|
||||
if (show_another_window) {
|
||||
// Pass a pointer to our bool variable (the window
|
||||
// will have a closing button that will clear the bool
|
||||
// when clicked)
|
||||
|
@ -163,8 +173,11 @@ main()
|
|||
|
||||
// Rendering
|
||||
ImGui::Render();
|
||||
glViewport(0, 0, (int)io.DisplaySize.x, (int)io.DisplaySize.y);
|
||||
glClearColor(clear_color.x * clear_color.w, clear_color.y * clear_color.w, clear_color.z * clear_color.w, clear_color.w);
|
||||
glViewport(0, 0, (int) io.DisplaySize.x,
|
||||
(int) io.DisplaySize.y);
|
||||
glClearColor(clear_color.x * clear_color.w,
|
||||
clear_color.y * clear_color.w,
|
||||
clear_color.z * clear_color.w, clear_color.w);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||
SDL_GL_SwapWindow(window);
|
||||
|
@ -179,7 +192,6 @@ main()
|
|||
SDL_DestroyWindow(window);
|
||||
SDL_Quit();
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue