Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
GWRon opened this issue Oct 10, 2023 · 1 comment

Comments

@GWRon
Copy link
Contributor

GWRon commented Oct 10, 2023

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
Copy link
Contributor Author

GWRon commented Oct 10, 2023

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...) ?

@GWRon GWRon changed the title SDL + MaxGUI (System drivers already initialized) SDL + MaxGUI (System drivers already initialized) -> sdlgraphics AttachGraphics not working? Oct 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant