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.
function TEmbedWindow.Start: Boolean;
var
W: TXID;
begin
Result := False;
// FAssociate is a TWinControl and has a x windows handle
if FAssociate = nil then
Exit;
// I have also tried with just SDL_INIT_VIDEO or SDL_INIT_TIMER
if SDL_Init(SDL_INIT_EVERYTHING) < 0 then
Exit;
// Configure the OpenGL context request
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
// This gets the x window handle from a gtk2 based control
W := GDK_WINDOW_XWINDOW(PGtkWidget(PtrUInt(FAssociate.Handle))^.window);
// This line stops all execution
FWindow := SDL_CreateWindowFrom(Pointer(W));
// The program exits from the line above
if FWindow = nil then
Exit;
FCtx := SDL_GL_CreateContext(FWindow);
if FCtx = nil then
Exit;
SDL_GL_MakeCurrent(FWindow, FCtx);
FStarted := LoadGL(SDL_GL_GetProcAddress);
Result := FStarted;
end;