SetGraphicsDriver() during runtime?

BlitzMax Forums/BlitzMax GUI Programming/SetGraphicsDriver() during runtime?

Hi all!

Simple Question. Can I switch between:

"SetGraphicsDriver D3D7Max2DDriver()"

and

"SetGraphicsDriver GLMax2DDriver()"

during runtime in my GUI app?

That means: Will the driver be changed instantly or do I have to restart the app for that?!? (Windows OS)

It doesn't seem to work without a restart...


Grisu

I would guess you'd have to setup your graphics etc. again, after a change of graphics driver...

What do you mean by setup your gfx? Do I have to destroy my MainWindow Gadget and recreate it anew?

I have already tried hiding and reshowing the window after calling setgraphicsdriver. But this has no effect also.

This seems to work...

' createcanvas.bmx

Strict 

Global GAME_WIDTH=320
Global GAME_HEIGHT=280

Local nextDriver$ = "GL"

' create a centered window with client size GAME_WIDTH,GAME_HEIGHT

Local wx=(ClientWidth(Desktop())-GAME_WIDTH)/2
Local wy=(ClientHeight(Desktop())-GAME_HEIGHT)/2

Local window:TGadget=CreateWindow("My Canvas",wx,wy,GAME_WIDTH,GAME_HEIGHT,Null,WINDOW_TITLEBAR|WINDOW_CLIENTCOORDS)

' create a canvas for our game

Local canvas:TGadget=CreateCanvas(0,0,320,240,window)
SetGraphics CanvasGraphics(canvas)' Only needed here for the _max2ddriver.ToString() below

Local changeButton:TGadget = CreateButton("Set " + nextDriver$ + " Driver", 8, 248, 100, 24, window)
Local driverLabel:TGAdget = CreateLabel("Currently using - " + _max2ddriver.ToString(), 100, 254, 220, 24,..
																				window, LABEL_CENTER) 

' create an update timer

CreateTimer 60

While WaitEvent()
	Select EventID()
		Case EVENT_TIMERTICK
			RedrawGadget canvas

		Case EVENT_GADGETPAINT
			SetGraphics CanvasGraphics(canvas)
			SetOrigin 160,120
			SetLineWidth 5
			Cls
			Local t=MilliSecs()
			DrawLine 0,0,120*Cos(t),120*Sin(t)
			DrawLine 0,0,80*Cos(t/60),80*Sin(t/60)
			Flip

		Case EVENT_WINDOWCLOSE
			FreeGadget canvas
			End

		Case EVENT_APPTERMINATE
			End
		
		Case EVENT_GADGETACTION
			If currentEvent.source = changeButton
				If nextDriver$ = "GL"
					nextDriver$ = "DX"
					changeButton.SetText("Set " + nextDriver$ + " Driver")
					FreeGadget canvas
					SetGraphicsDriver GLMax2DDriver()
				Else
					nextDriver$ = "GL"
					changeButton.SetText("Set " + nextDriver$ + " Driver")
					FreeGadget canvas
					SetGraphicsDriver D3D7Max2DDriver()				
				EndIf
				
				canvas:TGadget=CreateCanvas(0,0,320,240,window)
				SetGraphics CanvasGraphics(canvas) ' Only needed here for the _max2ddriver.ToString() below
				driverLabel.SetText("Currently using - " + _max2ddriver.ToString())
			EndIf
					
	End Select
Wend


Some posts have been deleted here, stange?!? :(

Anyway, there are about 8 different canvas in my app and recreating them all in realtime looks ugly.

Was worth a try. I think the user will have to live with a app restart by hand.

Thanks for all the replies!

As a user, I'd prefer an app to have a glitchy real time change (I wouldn't expect it to be smooth, in fact) to one that made me restart.

It's obviously your choice though. ;o)