Using FLTK 1.3.3 with Panda3D 1.9.1

Using FLTK 1.3.3 with Panda3D 1.9.1, I am trying to create a FLTK window and then re-parenting the Panda3D window to the FLTK window.

Things I have seen mentioned (documentation and elsewhere):

The FLTK window works without a Panda3D window and vice versa.

I tried using the function described on the following page to get a Windows Window Handle (HWND):
https://support.microsoft.com/en-us/kb/124103
More info:
https://msdn.microsoft.com/en-us/library/windows/desktop/ms683175%28v=vs.85%29.aspx

I have also tried the following:

PandaFramework framework;
framework.open_framework( argc, argv );

WindowProperties newProperties;
framework.get_default_window_props( newProperties );

HWND *hwnd = fl_xid( window );
WindowHandle *whnd = new WindowHandle( hwnd );

newProperties.set_parent_window( whnd );

AFAIK, the HWND is a WindowHandle::OSHandle in Panda3D.
Thus by retrieving the HWND from the FLTK window, I should be able to then use this to create a WindowHandle and then apply it to the WindowProperties.

Note that I didn’t find GraphicsPipe::make_window_handle(), does it still even exist?.

I must be doing something horribly wrong, because the compiler errors I am receiving don’t have anything to do with what I’m trying to achieve.

Can anybody help me out here? Any tips or pointers are greatly appreciated!

Try this:

newProperties.set_parent_window(NativeWindowHandle::make_hwnd(hwnd));

where hwnd is the HWND you received from fl_xid.

I’m assuming you’re then passing the newProperties in through open_window, or something like that?

Thanks, I’ll try that first thing in the morning.

Yes, I pass the newProperties to open_window() together with a BufferCreationFlag (2nd parameter).

I’m not sure what Panda understands as being a Window, so I don’t know if it needs BF_require_window or not. Which of the flags do I need here?

[size=150]Edit:[/size]

I got rid of the weird compiler errors I was receiving before. Had something to do with WinSock being included more than once. And it was only occurring while using Panda and FLTK at the same time.

Solution:
define

_WINSOCKAPI_

Now that I got rid of those errors, I fiddled around with that code you provided.
I ended up with the following, which doesn’t cause any errors, but crashes the application on start:

#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/x.h>

#include "pandaFramework.h"
#include "pandaSystem.h"
#include "pandabase.h"
#include "nativeWindowHandle.h"

int main( int argc, char **argv )
{
	Fl_Window *window = new Fl_Window( 1280, 720 );
	window->end();
	window->show( argc, argv );

	// Open a new window framework:
	PandaFramework framework;
	framework.open_framework( argc, argv );
	framework.set_window_title( "Panda Window" );
	framework.enable_default_keys();

	// Create new WindowProperties to be applied to the window:
	WindowProperties newProperties;
	framework.get_default_window_props( newProperties );

	HWND *hwnd = (HWND *)fl_xid( window );
	newProperties.set_parent_window(NativeWindowHandle::make_win( *hwnd ));

	// Open the window with our custom WindowProperties applied:
	WindowFramework *pWindow = framework.open_window(newProperties, GraphicsPipe::BF_require_window);
	//WindowFramework *pWindow = framework.open_window(newProperties, GraphicsPipe::BF_refuse_window);


	return Fl::run();
}

Note that

NativeWindowHandle::make_hwnd()

doesn’t exist in Panda3D 1.9.1, but

NativeWindowHandle::make_win()

does.

Any further thoughts?

[size=150]Edit2:[/size]
I’ve converted the pointer to a regular variable for sake of simplicity.

Notes:

inline Window fl_xid(const Fl_Window* w)

Window is a typedef of HWND.
Thus I need to cast the return value of fl_xid() to HWND.

I tried to pass the flag BF_refuse_window to open_window(), which resulted in not crashing the application and output in the console window. See the attachment.


I’d rather not double-post, but here’s a topic boost in case anybody missed it.

Also rdb, do you have any more ideas?
Seeing the output in the console, I think it might help to request a FrameBuffer with the same properties as the FrameBuffer it got. I didn’t get around to trying it yet, but when I get the time, I’ll try.

Don’t use BF_refuse_window. That’s for opening an offscreen buffer. You shouldn’t need BF_require_window (it should already be set for you, I think).

Are you sure fl_xid returns a HWND* and not a HWND? If things are as you describe, it should actually be something like this:

   HWND hwnd = (HWND)fl_xid( window );
   newProperties.set_parent_window(NativeWindowHandle::make_win( hwnd ));

You’ll also want to call set_origin(0, 0) on the WindowProperties to make sure the window doesn’t get an offset.

If this still doesn’t help, I could suggest that perhaps the window hasn’t been fully opened yet at the time you try to open the Panda window, and you may need to wait for a “create” event to be sent by fltk, or something like that.

Thanks for the continued guidance!

I had suspected as much from BF_refuse_window.
Shortly after posting I converted the HWND line to what you have mentioned just now, but it didn’t make a difference. I will obviously keep it like this now.

I’ll try to set the origin on the WindowProperties like you suggested and perhaps wait on a FLTK window creation event to open the Panda window.

Something to be noted: I’ve begun to dabble with wxWidgets instead of FLTK, I’ll see if there’s a difference between the two.