SFML community forums

Help => Window => Topic started by: JonathanCR on August 18, 2020, 11:10:24 pm

Title: Using WindowHandle to allow SFML to render onto existing windows
Post by: JonathanCR on August 18, 2020, 11:10:24 pm
Hi everyone,

Please forgive my ineptitude. I'm a beginner!

I'm using nanogui (https://github.com/mitsuba-renderer/nanogui) in my program and would like to allow SFML to render onto a nanogui window (or screen, as it calls it). I understand that I can do this by getting the window handle of the nanogui window, but I don't understand how to do this.

I have tried this:

    int scwidth=1024;
    int scheight=768;

    nanogui::Screen *screen=nullptr;

    screen=new nanogui::Screen(Vector2i(scwidth,scheight),"Project Name");
   
    sf::Window (sf::WindowHandle(screen));

But that doesn't work, as I didn't really think it would. It builds fine and runs, but hits the dreaded EXC_BAD_ACCESS at that last line.

So how *do* I get the window handle of the nanogui window and use it in the sf::Window constructor?? I'm doing this on Mac in Xcode.

Thank you for any light anyone can shed on this...
Title: Re: Using WindowHandle to allow SFML to render onto existing windows
Post by: eXpl0it3r on August 21, 2020, 11:10:28 am
What's the call stack when you run it through the debugger?
Title: Re: Using WindowHandle to allow SFML to render onto existing windows
Post by: fallahn on August 21, 2020, 08:42:22 pm
From what I understand from the nanogui docs (https://nanogui.readthedocs.io/en/latest/api/classnanogui_1_1Screen.html) what you're doing won't work because your 'screen' variable is just a pointer to the nanogui Screen class. According to the documentation nanogui uses glfw for window creation, and you can get a pointer to the GLFWwindow using the glfwWindow() function in the Screen class. Once you have that you can include glfw3native.h (https://www.glfw.org/docs/latest/glfw3native_8h.html) which provides a series of platform specific functions for returning native window handles. On macOS I assume you need glfwGetCocoaWindow () (https://www.glfw.org/docs/latest/group__native.html#gac3ed9d495d0c2bb9652de5a50c648715)
Title: Re: Using WindowHandle to allow SFML to render onto existing windows
Post by: JonathanCR on August 22, 2020, 10:55:46 pm
Thank you! This is really helpful. I shall see if I can work it out.