Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Using WindowHandle to allow SFML to render onto existing windows  (Read 1290 times)

0 Members and 1 Guest are viewing this topic.

JonathanCR

  • Newbie
  • *
  • Posts: 7
    • View Profile
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...

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 9984
    • View Profile
    • development blog
    • Email
Re: Using WindowHandle to allow SFML to render onto existing windows
« Reply #1 on: August 21, 2020, 11:10:28 am »
What's the call stack when you run it through the debugger?
Official FAQ: https://www.sfml-dev.org/faq.php
Nightly Builds: https://www.nightlybuilds.ch/
——————————————————————
Dev Blog: https://dev.my-gate.net/
Thor: http://www.bromeon.ch/libraries/thor/

fallahn

  • Sr. Member
  • ****
  • Posts: 445
  • Buns.
    • View Profile
    • Trederia
Re: Using WindowHandle to allow SFML to render onto existing windows
« Reply #2 on: August 21, 2020, 08:42:22 pm »
From what I understand from the nanogui docs 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 which provides a series of platform specific functions for returning native window handles. On macOS I assume you need glfwGetCocoaWindow ()

JonathanCR

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Using WindowHandle to allow SFML to render onto existing windows
« Reply #3 on: August 22, 2020, 10:55:46 pm »
Thank you! This is really helpful. I shall see if I can work it out.

 

anything