Changing screen modes within a program?
Blitz3D Forums/Blitz3D Programming/Changing screen modes within a program?| 
 | ||
| This is probably a really dumb question, but is it possible to make it so that a program's screen mode can be changed whilst it is running? I want to give players the choice of playing at full-screen, windowed, or minimized at the beginning of the game. | 
| 
 | ||
| Yep! Just use any trigger you like, keypress, etc, and the screenmode will change automatically :) | 
| 
 | ||
| Unfortunately it isn't as simple as that. The graphics mode of the main program cannot be apart of the program's main loop, which means "triggering" a screen mode change through a variable is impossible. | 
| 
 | ||
| Yes it works, I did it for years. I've put together a short and easy example for ya. ;) You will need to provide the picture files yourself though! The key to making this work, you have to reload the images every time you change GFX modes. This is handled automatically in the UserInput() function. 
Global redFaceGFX
SetGFXMode(1)
LoadGFX()
Repeat
	Cls
	DrawImage redFaceGFX, 0, 0
	Flip
	
	UserInput()
	
Until KeyHit(1)
End
Function SetGFXMode(index)
	If index = 1
		Graphics 800, 600
		
	EndIf
	
	If index = 2
		Graphics 1280, 1024
		
	EndIf
	
	SetBuffer BackBuffer()
	
End Function
Function LoadGFX()
	redFaceGFX = LoadImage("redface.png")
	
End Function
Function UserInput()
	If KeyHit(2)
		SetGFXMode(1)
		LoadGFX()
		
	EndIf
	
	If KeyHit(3)
		SetGFXMode(2)
		LoadGFX()
		
	EndIf
	
End Function
 | 
| 
 | ||
| I was actually thinking of making something along the lines of a program launcher, where after you select your desired resolution, the launcher closes and the main program begins. | 
| 
 | ||
| ExecFile() may be useful in that case. | 
| 
 | ||
| Problem with ExecFile it will cause the launcher to stay open until the sub-program closes. I do have a better way of doing what you need though, if you can bare with me for a bit. ;) | 
| 
 | ||
| I actually managed to create my own launcher using your example as reference. Thanks for the help :) | 
| 
 | ||
| It's good to see you make the effort, here's how I would do it though BTW. ;) By doing it this way you don't need to open up a sub program with ExecFile() Global redFaceGFX
Launcher()
Repeat
	Cls
	DrawImage redFaceGFX, 0, 0
	Flip
	
Until KeyHit(1)
End
Function SetGFXMode(index)
	If index = 1
		Graphics 800, 600
		
	EndIf
	
	If index = 2
		Graphics 1280, 1024
		
	EndIf
	
	SetBuffer BackBuffer()
	
End Function
Function LoadGFX()
	redFaceGFX = LoadImage("redface.png")
	
End Function
Function Launcher()
	Local modeSelected = 0
	
	SetBuffer BackBuffer()
	
	While modeSelected = 0
		Cls
		Text 0, 0, "Press [1] for: GFXMode 800 x 600"
		Text 0, 20, "Press [2] for: GFXMode 1280 x 1024"
		
		Flip
		
		If KeyHit(2)
			modeSelected = 1
			
			SetGFXMode(1)
			LoadGFX()
			
		EndIf
		
		If KeyHit(3)
			modeSelected = 1
			
			SetGFXMode(2)
			LoadGFX()
			
		EndIf
		
	Wend
	
End Function
 | 
| 
 | ||
| The code I posted above runs before setting the GFX mode, it will open up in a window when no GFX mode is specified. | 
| 
 | ||
| Very nice and readable. I'll give this example further inspection and see what I can do with it. Once again, thanks :) | 
| 
 | ||
| Okies!, glad to be of help. :) | 
| 
 | ||
| The old examples are a goldmine ... There is a launcher which checks the available screenmodes etc etc ... it is easy to modify ... own start image, prefered selections, saving users choice to an ini file, etc. Its in the directory samples/mak (for Mark Sibly) and is called start.bb | 
| 
 | ||
| It's been years since I've checked those examples. I'm gonna take another peek at them for reference (and nostalgia). |