bmx-ng / sdl.mod

SDL backend for BlitzMax
7 stars 6 forks source link

SDL + MaxGUI (System drivers already initialized) -> sdlgraphics AttachGraphics not working? #56

Open GWRon opened 1 year ago

GWRon commented 1 year ago

I would like to see MaxGUI working with SDL (so eg sdlrendermax2d).

For now this is not possible as MaxGUI's GTK3Driver initializes its own systemdriver. First step is extending this system driver to use TSDLSystem instead ... also

Type TGTK3SystemDriver Extends TSDLSystemDriver Implements IWrappedSystemDriver

(I actually copied the whole mode and made it a maxgui.mod/SDLGTK3MaxGUI.mod)

Next thing to comment out is

'?linux
        ' attach max's fd to a glib event source so things like timers can work
'       guisystem.gsource = bmx_gtk_event_source_new(bbSystemAsyncFD())
'?

but I am not sure if it needs something similar at the end - or if SDL handles it for us already.

It then compiles the following - but segfaults on "cls" (null element) and asserts that AttachGraphics failed:Assert failedAttachGraphics failed:

SuperStrict 
Framework Brl.StandardIO
Import MaxGui.SDLGTK3MaxGUI
Import SDL.SDLRendermax2D
Import SDL.SDLTimer
Import brl.EventQueue
Global window:TGadget=CreateWindow("Canvas",100,100, 600, 400 ,Null,WINDOW_TITLEBAR)
Global canvas:TGadget=CreateCanvas(100,100, 400,200,window)
Global X:Int=150,Y:Int=100, Xadd:Int=1, YAdd:Int=1
CreateTimer 60

While WaitEvent()
    Select EventID()
        Case EVENT_TIMERTICK
            GameLogic
            RedrawGadget canvas
        Case EVENT_GADGETPAINT
            Draw
        Case EVENT_WINDOWCLOSE, EVENT_APPTERMINATE
            End
    End Select
Wend

Function Draw()
    SetGraphics CanvasGraphics(Canvas)
        Cls
        DrawOval X,Y,20,20
    Flip 0
End Function 

Function GameLogic()
    X:+ Xadd
    Y:+ Yadd
    If X<0 Or X>400 Then Xadd=-Xadd
    If Y<0 Or Y>200 Then Yadd=-Yadd
End Function 

(code adjusted from Midimasters sample at discord)

GWRon commented 1 year ago

gtkgadget.bmx:

    Method AttachGraphics:TGraphics( flags:Long )
        Mode = flags
    End Method

    Method CanvasGraphics:TGraphics()
        If Not canvas Then
            canvas = BRL.Graphics.AttachGraphics(gdk_x11_window_get_xid(gtk_widget_get_window(handle)), Mode)
        End If

        Return canvas
    End Method

fails to attach the graphics. BTW it is interesting to see the Method AttachGraphics to say it returns a TGraphics instance but does not return ... anything (than null)

Maybe sdlgraphics.mod/sdlgraphics.bmx:

    Method AttachGraphics:TSDLGraphics( widget:Byte Ptr,flags:Long ) Override
        Local t:TSDLGraphics=New TSDLGraphics
        't._context=bbGLGraphicsAttachGraphics( widget,flags )
        Return t
    End Method

needs some ... functionality (context...) ?