|
@@ -27,17 +27,40 @@ static void glfw_error_callback(int error, const char* description)
|
|
|
|
|
|
int main(int, char**)
|
|
|
{
|
|
|
+ glfwSetErrorCallback(glfw_error_callback);
|
|
|
+ if (!glfwInit())
|
|
|
+ return 1;
|
|
|
+
|
|
|
+ // Create window with graphics context
|
|
|
+ float main_scale = ImGui_ImplGlfw_GetContentScaleForMonitor(glfwGetPrimaryMonitor()); // Valid on GLFW 3.3+ only
|
|
|
+ glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
|
|
|
+ GLFWwindow* window = glfwCreateWindow((int)(1280 * main_scale), (int)(800 * main_scale), "Dear ImGui GLFW+Metal example", nullptr, nullptr);
|
|
|
+ if (window == nullptr)
|
|
|
+ return 1;
|
|
|
+
|
|
|
// Setup Dear ImGui context
|
|
|
IMGUI_CHECKVERSION();
|
|
|
ImGui::CreateContext();
|
|
|
ImGuiIO& io = ImGui::GetIO(); (void)io;
|
|
|
- io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
|
|
|
- io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
|
|
|
+ io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
|
|
|
+ io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
|
|
|
|
|
|
- // Setup style
|
|
|
+ // Setup Dear ImGui style
|
|
|
ImGui::StyleColorsDark();
|
|
|
//ImGui::StyleColorsLight();
|
|
|
|
|
|
+ // Setup scaling
|
|
|
+ ImGuiStyle& style = ImGui::GetStyle();
|
|
|
+ style.ScaleAllSizes(main_scale); // Bake a fixed style scale. (until we have a solution for dynamic style scaling, changing this requires resetting Style + calling this again)
|
|
|
+ style.FontScaleDpi = main_scale; // Set initial font scale. (using io.ConfigDpiScaleFonts=true makes this unnecessary. We leave both here for documentation purpose)
|
|
|
+
|
|
|
+ id <MTLDevice> device = MTLCreateSystemDefaultDevice();
|
|
|
+ id <MTLCommandQueue> commandQueue = [device newCommandQueue];
|
|
|
+
|
|
|
+ // Setup Platform/Renderer backends
|
|
|
+ ImGui_ImplGlfw_InitForOpenGL(window, true);
|
|
|
+ ImGui_ImplMetal_Init(device);
|
|
|
+
|
|
|
// Load Fonts
|
|
|
// - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them.
|
|
|
// - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple.
|
|
@@ -54,24 +77,6 @@ int main(int, char**)
|
|
|
//ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf");
|
|
|
//IM_ASSERT(font != nullptr);
|
|
|
|
|
|
- // Setup window
|
|
|
- glfwSetErrorCallback(glfw_error_callback);
|
|
|
- if (!glfwInit())
|
|
|
- return 1;
|
|
|
-
|
|
|
- // Create window with graphics context
|
|
|
- glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
|
|
|
- GLFWwindow* window = glfwCreateWindow(1280, 800, "Dear ImGui GLFW+Metal example", nullptr, nullptr);
|
|
|
- if (window == nullptr)
|
|
|
- return 1;
|
|
|
-
|
|
|
- id <MTLDevice> device = MTLCreateSystemDefaultDevice();
|
|
|
- id <MTLCommandQueue> commandQueue = [device newCommandQueue];
|
|
|
-
|
|
|
- // Setup Platform/Renderer backends
|
|
|
- ImGui_ImplGlfw_InitForOpenGL(window, true);
|
|
|
- ImGui_ImplMetal_Init(device);
|
|
|
-
|
|
|
NSWindow *nswin = glfwGetCocoaWindow(window);
|
|
|
CAMetalLayer *layer = [CAMetalLayer layer];
|
|
|
layer.device = device;
|