Minor fixes to example_sdl_metal and a changelog entry.
Add example_sdl_metal to CI builds.
Closes #3017.
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index a874bff..ff83bd3 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -241,6 +241,9 @@
- name: Build example_glfw_metal
run: make -C examples/example_glfw_metal
+ - name: Build example_sdl_metal
+ run: make -C examples/example_sdl_metal
+
- name: Build example_sdl_opengl2
run: make -C examples/example_sdl_opengl2
if: github.event_name == 'schedule'
diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt
index 736cb44..66c5160 100644
--- a/docs/CHANGELOG.txt
+++ b/docs/CHANGELOG.txt
@@ -31,6 +31,15 @@
-----------------------------------------------------------------------
+ VERSION 1.76 WIP (In Progress)
+-----------------------------------------------------------------------
+
+Other Changes:
+
+- Backends: Added SDL2+Metal example application. (#3017) [@coding-jackalope]
+
+
+-----------------------------------------------------------------------
VERSION 1.75 (Released 2020-02-10)
-----------------------------------------------------------------------
diff --git a/examples/README.txt b/examples/README.txt
index 5bd16be..5d07a21 100644
--- a/examples/README.txt
+++ b/examples/README.txt
@@ -190,7 +190,7 @@
example_glfw_metal/
GLFW (Mac) + Metal example.
- = main.mm + imgui_impl_glfw.cpp + imgui_impl_metal.mm.
+ = main.mm + imgui_impl_glfw.cpp + imgui_impl_metal.mm
example_glfw_opengl2/
GLFW + OpenGL2 example (legacy, fixed pipeline).
@@ -237,6 +237,10 @@
= main.cpp + imgui_impl_sdl.cpp + imgui_impl_dx11.cpp
This to demonstrate usage of DirectX with SDL.
+example_sdl_metal/
+ SDL2 (Mac) + Metal example.
+ = main.mm + imgui_impl_sdl.cpp + imgui_impl_metal.mm
+
example_sdl_opengl2/
SDL2 (Win32, Mac, Linux etc.) + OpenGL example (legacy, fixed pipeline).
= main.cpp + imgui_impl_sdl.cpp + imgui_impl_opengl2.cpp
diff --git a/examples/example_glfw_metal/main.mm b/examples/example_glfw_metal/main.mm
index 45dbb37..d6f9ae3 100644
--- a/examples/example_glfw_metal/main.mm
+++ b/examples/example_glfw_metal/main.mm
@@ -1,9 +1,11 @@
-// ImGui - standalone example application for GLFW + Metal, using programmable pipeline
-// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp.
+// dear imgui: standalone example application for GLFW + Metal, using programmable pipeline
+// If you are new to dear imgui, see examples/README.txt and documentation at the top of imgui.cpp.
+// (GLFW is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan/Metal graphics context creation, etc.)
#include "imgui.h"
#include "imgui_impl_glfw.h"
#include "imgui_impl_metal.h"
+#include <stdio.h>
#define GLFW_INCLUDE_NONE
#define GLFW_EXPOSE_NATIVE_COCOA
@@ -13,8 +15,6 @@
#import <Metal/Metal.h>
#import <QuartzCore/QuartzCore.h>
-#include <stdio.h>
-
static void glfw_error_callback(int error, const char* description)
{
fprintf(stderr, "Glfw Error %d: %s\n", error, description);
diff --git a/examples/example_glfw_opengl2/main.cpp b/examples/example_glfw_opengl2/main.cpp
index 5630b6c..a50b463 100644
--- a/examples/example_glfw_opengl2/main.cpp
+++ b/examples/example_glfw_opengl2/main.cpp
@@ -1,6 +1,6 @@
// dear imgui: standalone example application for GLFW + OpenGL2, using legacy fixed pipeline
// If you are new to dear imgui, see examples/README.txt and documentation at the top of imgui.cpp.
-// (GLFW is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.)
+// (GLFW is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan/Metal graphics context creation, etc.)
// **DO NOT USE THIS CODE IF YOUR CODE/ENGINE IS USING MODERN OPENGL (SHADERS, VBO, VAO, etc.)**
// **Prefer using the code in the example_glfw_opengl2/ folder**
diff --git a/examples/example_glfw_opengl3/main.cpp b/examples/example_glfw_opengl3/main.cpp
index ef7ddfe..55b379d 100644
--- a/examples/example_glfw_opengl3/main.cpp
+++ b/examples/example_glfw_opengl3/main.cpp
@@ -1,6 +1,6 @@
// dear imgui: standalone example application for GLFW + OpenGL 3, using programmable pipeline
// If you are new to dear imgui, see examples/README.txt and documentation at the top of imgui.cpp.
-// (GLFW is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.)
+// (GLFW is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan/Metal graphics context creation, etc.)
#include "imgui.h"
#include "imgui_impl_glfw.h"
diff --git a/examples/example_sdl_directx11/main.cpp b/examples/example_sdl_directx11/main.cpp
index 812b40f..0a97325 100644
--- a/examples/example_sdl_directx11/main.cpp
+++ b/examples/example_sdl_directx11/main.cpp
@@ -1,6 +1,6 @@
// dear imgui: standalone example application for SDL2 + DirectX 11
// If you are new to dear imgui, see examples/README.txt and documentation at the top of imgui.cpp.
-// (SDL is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.)
+// (SDL is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan/Metal graphics context creation, etc.)
#include "imgui.h"
#include "imgui_impl_sdl.h"
diff --git a/examples/example_sdl_metal/main.mm b/examples/example_sdl_metal/main.mm
index 7801ca1..3cb1ea4 100644
--- a/examples/example_sdl_metal/main.mm
+++ b/examples/example_sdl_metal/main.mm
@@ -1,17 +1,16 @@
-// ImGui - standalone example application for GLFW + Metal, using programmable pipeline
-// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp.
+// Dear ImGui: standalone example application for SDL2 + Metal
+// If you are new to dear imgui, see examples/README.txt and documentation at the top of imgui.cpp.
+// (SDL is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan/Metal graphics context creation, etc.)
#include "imgui.h"
#include "imgui_impl_sdl.h"
#include "imgui_impl_metal.h"
-
-#include "SDL.h"
+#include <stdio.h>
+#include <SDL.h>
#import <Metal/Metal.h>
#import <QuartzCore/QuartzCore.h>
-#include <stdio.h>
-
int main(int, char**)
{
// Setup Dear ImGui binding
@@ -49,27 +48,17 @@
return -1;
}
- SDL_Window* window = SDL_CreateWindow(
- "Dear ImGui SDL+Metal example",
- SDL_WINDOWPOS_CENTERED,
- SDL_WINDOWPOS_CENTERED,
- 1280,
- 720,
- SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI
- );
+ // Inform SDL that we will be using metal for rendering. Without this hint initialization of metal renderer may fail.
+ SDL_SetHint(SDL_HINT_RENDER_DRIVER, "metal");
+ SDL_Window* window = SDL_CreateWindow("Dear ImGui SDL+Metal example", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);
if (window == NULL)
{
printf("Error creating window: %s\n", SDL_GetError());
return -2;
}
- SDL_Renderer* renderer = SDL_CreateRenderer(
- window,
- -1,
- SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC
- );
-
+ SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
if (renderer == NULL)
{
printf("Error creating renderer: %s\n", SDL_GetError());
@@ -125,7 +114,7 @@
// Start the Dear ImGui frame
ImGui_ImplMetal_NewFrame(renderPassDescriptor);
- ImGui_ImplSDL2_NewFrame_Metal(window);
+ ImGui_ImplSDL2_NewFrame(window);
ImGui::NewFrame();
// 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!).
diff --git a/examples/example_sdl_opengl2/main.cpp b/examples/example_sdl_opengl2/main.cpp
index b55cb22..ff54ec4 100644
--- a/examples/example_sdl_opengl2/main.cpp
+++ b/examples/example_sdl_opengl2/main.cpp
@@ -1,6 +1,6 @@
// dear imgui: standalone example application for SDL2 + OpenGL
// If you are new to dear imgui, see examples/README.txt and documentation at the top of imgui.cpp.
-// (SDL is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.)
+// (SDL is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan/Metal graphics context creation, etc.)
// **DO NOT USE THIS CODE IF YOUR CODE/ENGINE IS USING MODERN OPENGL (SHADERS, VBO, VAO, etc.)**
// **Prefer using the code in the example_sdl_opengl3/ folder**
diff --git a/examples/example_sdl_opengl3/main.cpp b/examples/example_sdl_opengl3/main.cpp
index a0cfe24..20801a1 100644
--- a/examples/example_sdl_opengl3/main.cpp
+++ b/examples/example_sdl_opengl3/main.cpp
@@ -1,6 +1,6 @@
// dear imgui: standalone example application for SDL2 + OpenGL
// If you are new to dear imgui, see examples/README.txt and documentation at the top of imgui.cpp.
-// (SDL is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.)
+// (SDL is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan/Metal graphics context creation, etc.)
// (GL3W is a helper library to access OpenGL functions since there is no standard header to access modern OpenGL functions easily. Alternatives are GLEW, Glad, etc.)
#include "imgui.h"
diff --git a/examples/imgui_impl_sdl.cpp b/examples/imgui_impl_sdl.cpp
index aac3b82..6917262 100644
--- a/examples/imgui_impl_sdl.cpp
+++ b/examples/imgui_impl_sdl.cpp
@@ -364,31 +364,3 @@
// Update game controllers (if enabled and available)
ImGui_ImplSDL2_UpdateGamepads();
}
-
-void ImGui_ImplSDL2_NewFrame_Metal(SDL_Window* window)
-{
- ImGuiIO& io = ImGui::GetIO();
- IM_ASSERT(io.Fonts->IsBuilt() && "Font atlas not built! It is generally built by the renderer back-end. Missing call to renderer _NewFrame() function? e.g. ImGui_ImplMetal_NewFrame().");
-
- // Setup display size (every frame to accommodate for window resizing)
- SDL_Renderer* renderer = SDL_GetRenderer(window);
- int w, h;
- int display_w, display_h;
- SDL_GetWindowSize(window, &w, &h);
- SDL_GetRendererOutputSize(renderer, &display_w, &display_h);
- io.DisplaySize = ImVec2((float)w, (float)h);
- if (w > 0 && h > 0)
- io.DisplayFramebufferScale = ImVec2((float)display_w / w, (float)display_h / h);
-
- // Setup time step (we don't use SDL_GetTicks() because it is using millisecond resolution)
- static Uint64 frequency = SDL_GetPerformanceFrequency();
- Uint64 current_time = SDL_GetPerformanceCounter();
- io.DeltaTime = g_Time > 0 ? (float)((double)(current_time - g_Time) / frequency) : (float)(1.0f / 60.0f);
- g_Time = current_time;
-
- ImGui_ImplSDL2_UpdateMousePosAndButtons();
- ImGui_ImplSDL2_UpdateMouseCursor();
-
- // Update game controllers (if enabled and available)
- ImGui_ImplSDL2_UpdateGamepads();
-}
diff --git a/examples/imgui_impl_sdl.h b/examples/imgui_impl_sdl.h
index 42da71e..a672ca8 100644
--- a/examples/imgui_impl_sdl.h
+++ b/examples/imgui_impl_sdl.h
@@ -22,8 +22,7 @@
IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForOpenGL(SDL_Window* window, void* sdl_gl_context);
IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForVulkan(SDL_Window* window);
IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForD3D(SDL_Window* window);
-IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForMetal(SDL_Window* window);
+IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForMetal(SDL_Window* window);
IMGUI_IMPL_API void ImGui_ImplSDL2_Shutdown();
IMGUI_IMPL_API void ImGui_ImplSDL2_NewFrame(SDL_Window* window);
-IMGUI_IMPL_API void ImGui_ImplSDL2_NewFrame_Metal(SDL_Window* window);
IMGUI_IMPL_API bool ImGui_ImplSDL2_ProcessEvent(const SDL_Event* event);