Skip to content

Empty windows with SDL2 renderer on macOS #5931

@JacobCZ

Description

@JacobCZ

Version/Branch of Dear ImGui:

Version: 1.89.1
Branch: master

Back-end/Renderer/Compiler/OS

Back-ends: imgui_impl_sdl.h, imgui_impl_sdlrenderer.h; SDL2 using Metal
Compiler: Apple clang 14.0.0 (am64-apple-darwin22.1.0)
Operating System: macOS Ventura 13.0

My Issue/Question:

I'm trying to render the demo window and one additional window. The window frames are both shown but only the additional window has a title and both of the windows are completely empty. The mouse also seems to be strangely offset. At first I thought this might somehow be a font issue because of the missing text but adding a custom font made no difference.

Screenshots/Video

image

Standalone, minimal, complete and verifiable example:

(error handling omitted for brevity)

int main(it argc, char* argv[]) {
  // Create SDL window and renderer
  SDL_Init(SDL_INIT_EVERYTHING);
  window = SDL_CreateWindow("Hello World", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_METAL);
  renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);

  // ImGui Init
  IMGUI_CHECKVERSION();
  ImGui::CreateContext();
  ImGuiIO& io = ImGui::GetIO();
  io.Fonts->AddFontDefault();
  ImGui_ImplSDL2_InitForSDLRenderer(window, renderer);
  ImGui_ImplSDLRenderer_Init(renderer);
  ImGui::StyleColorsDark();

  SDL_Event evt;
  while(true) {
    while(SDL_PollEvent(&evt)) {
      ImGui_ImplSDL2_ProcessEvent(&evt);
    }

    ImGui_ImplSDLRenderer_NewFrame();
    ImGui_ImplSDL2_NewFrame();
    ImGui::NewFrame();

    ImGui::ShowDemoWindow();

    ImGui::Begin("Debug");
    ImGui::Text("Hello World");
    ImGui::End();

    ImGui::Render();
    SDL_SetRenderDrawColor(renderer, 0x0, 0x0, 0x0, 0xFF);
    SDL_RenderClear(renderer);
    ImGui_ImplSDLRenderer_RenderDrawData(ImGui::GetDrawData());
    SDL_RenderPresent(renderer);
  }
}

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions