Sorry for bumping this thread. This was one of the first results I got when searching for this exact problem, and I want to share my findings that I manged to figure out during the last 24 hours.
I believe it's safe to assume that Windows and Linux draws things differently. As mentioned above, on Windows you could just pass a handle to a
TPanel and it'd use it as an SDL window to draw things. However that's not the case for Linux.
From the (extremely little!) testing that I did, I found out that the (possibly) only way you can successfully draw onto a GTK form is by drawing to a
TOpenGLControl from the
LazOpenGLContext package.
Trying to draw to a TPanel (the Windows way) ends up in failure, as the program closes at the
SDL_CreateWindowFrom function call with an error from X11 complaining about it being provided a bad window.
If I use additional function calls to get the correct pointer as mentioned in the 1st post (
GDK_WINDOW_XWINDOW( PGtkWidget( PtrUInt( FAssociate.Handle ))^.window );), it does render to some controls, but the controls then repaint themselves to their default programmed look.
However, when passing the
TOpenGLControl.Handle, said control gets used as an SDL window and you can actually draw to it.
Relevant units (don't forget to add LazOpenGLContext to your project's dependencies):
uses
{$IFDEF UNIX}
gtk2, gdk2x,
{$ENDIF}
OpenGLContext, SDL2;
Relevant code:
var
OpenGLControl: TOpenGLControl;
sdlWindow1: PSDL_Window;
...
{$IFDEF MSWINDOWS}
sdlWindow1 := SDL_CreateWindowFrom(Pointer(OpenGLControl.Handle));
{$ENDIF}
{$IFDEF UNIX}
sdlWindow1 := SDL_CreateWindowFrom(
Pointer(GDK_WINDOW_XWINDOW(
PGtkWidget(PtrUInt(OpenGLControl.Handle))^.window)
)
);
{$ENDIF}
It works for me on Linux Mint (under X11), Windows, and I tried with a VM of a Debian install running Wayland too (image attached bellow).
I'm also attaching the demo project.