Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty windows with SDL2 renderer on macOS #5931

Closed
JacobCZ opened this issue Nov 29, 2022 · 4 comments
Closed

Empty windows with SDL2 renderer on macOS #5931

JacobCZ opened this issue Nov 29, 2022 · 4 comments

Comments

@JacobCZ
Copy link

JacobCZ commented Nov 29, 2022

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);
  }
}
@ocornut
Copy link
Owner

ocornut commented Nov 29, 2022

  1. can you confirm that example_sdl_sdlrenderer/main.cpp is exhibit the same issue?

  2. The rendering issue seems like the scissoring is off:

  • either related to FrameBufferScale
  • either the same offset you have with the mouse are applied to scissoring rectangle, meaning text is clipped.
  1. Perhaps mouse issue is also a FrameBufferScale issue?

Out of curiosity try to remove the SDL_WINDOW_ALLOW_HIGHDPI flag.

We haven't really standardized setting/applying framebufferscale but it is currently a bit of a mess, hence my rather obtuse answer ( = I don't have full answer).

Links:
https://github.com/ocornut/imgui/issues?q=label%3Aosx%2Fios+label%3Adpi
dpi

Notice in ImGui_ImplSDLRenderer_RenderDrawData():

// If there's a scale factor set by the user, use that instead
// If the user has specified a scale factor to SDL_Renderer already via SDL_RenderSetScale(), SDL will scale whatever we pass
// to SDL_RenderGeometryRaw() by that scale factor. In that case we don't want to be also scaling it ourselves here.
float rsx = 1.0f;
float rsy = 1.0f;
SDL_RenderGetScale(bd->SDLRenderer, &rsx, &rsy);
ImVec2 render_scale;
render_scale.x = (rsx == 1.0f) ? draw_data->FramebufferScale.x : 1.0f;
render_scale.y = (rsy == 1.0f) ? draw_data->FramebufferScale.y : 1.0f;

@JacobCZ
Copy link
Author

JacobCZ commented Nov 29, 2022

example_sdl_sdlrenderer/main.cpp has the same issue...
image

Removing SDL_WINDOW_ALLOW_HIGHDPI seems to fix the issue and everything seems to be rendering at a reasonable scale for a 14 inch retina screen (with a very slightly blurry text with the default font, not visible on a screenshot and looks fine on a 1080p screen so probably not an ImGUI problem). Also solves the mouse offset issue.

image

@ocornut ocornut added the dpi label Nov 29, 2022
@ocornut
Copy link
Owner

ocornut commented Nov 29, 2022

Can you debug step into the beginning of ImGui_ImplSDLRenderer_RenderDrawData() and report all the values?

They are not hard problems to solve but I don’t have a Mac, I’ll want to spend more time on backend dpi issue on Mac for 1.90

ocornut added a commit that referenced this issue Jan 31, 2023
…play is correct on a Retina display (albeit lower-res as our other unmodified examples). (#6121, #6065, #5931).
@ocornut
Copy link
Owner

ocornut commented Jan 31, 2023

Hello,
I have added SDL_RenderSetScale() in 5a3f82e to make this consistent across examples for now. Fuller hi-dpi support on Mac in the examples app will be address separately but this fixes this issue.

@ocornut ocornut closed this as completed Jan 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants