Recent

Author Topic: Creating a SDL child window on a form or panel control?  (Read 214 times)

sysrpl

  • Sr. Member
  • ****
  • Posts: 286
    • Get Lazarus
Creating a SDL child window on a form or panel control?
« on: July 03, 2022, 03:44:31 pm »
I am attempting to use SDL2 on Linux (gtk2 widgetset) to create an OpenGL window inside a child control. I got the idea or impression that this was possible using the SDL_CreateWindowFrom function of SDL2, but all execution stops when I call the function.

Here is a bit of code from my TEmbedWindow class that is attempting to wrap a control / SDL OpenGL together in a class.

Does anyone have any suggestions as to how to get this working? Currently when the line with SDL_CreateWindowFrom  is reached, my program just exits.

Thank you for any suggestions you might have.

Code: Pascal  [Select][+][-]
  1. function TEmbedWindow.Start: Boolean;
  2. var
  3.   W: TXID;
  4. begin
  5.   Result := False;
  6.   // FAssociate is a TWinControl and has a x windows handle
  7.   if FAssociate = nil then
  8.     Exit;
  9.   // I have also tried with just SDL_INIT_VIDEO or SDL_INIT_TIMER
  10.   if SDL_Init(SDL_INIT_EVERYTHING) < 0 then
  11.     Exit;
  12.   // Configure the OpenGL context request
  13.   SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
  14.   SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
  15.   SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
  16.   SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
  17.   SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK,      SDL_GL_CONTEXT_PROFILE_ES);
  18.   // This gets the x window handle from a gtk2 based control
  19.   W := GDK_WINDOW_XWINDOW(PGtkWidget(PtrUInt(FAssociate.Handle))^.window);
  20.   // This line stops all execution
  21.   FWindow := SDL_CreateWindowFrom(Pointer(W));
  22.   // The program exits from the line above
  23.   if FWindow = nil then
  24.     Exit;
  25.   FCtx := SDL_GL_CreateContext(FWindow);
  26.   if FCtx = nil then
  27.     Exit;
  28.   SDL_GL_MakeCurrent(FWindow, FCtx);
  29.   FStarted := LoadGL(SDL_GL_GetProcAddress);
  30.   Result := FStarted;
  31. end;
  32.  

hukka

  • New member
  • *
  • Posts: 6
  • ookami
    • Website
Re: Creating a SDL child window on a form or panel control?
« Reply #1 on: July 03, 2022, 07:46:30 pm »
I haven't tried this on Linux, but on Windows I can successfully embed SDL2 into a TPanel with
Code: Pascal  [Select][+][-]
  1. SDL_CreateWindowFrom(Pointer(HostPanel.Handle));

 

TinyPortal © 2005-2018