Full Screen or Windowed

BlitzPlus Forums/BlitzPlus Programming/Full Screen or Windowed

uwdesign(Posted 2003) [#1]
Hi all,

While i've only just got b+. I'm already wondering how best to go about building, well, converting an existing bb2d program to B+. While it's already running my main concern at the moment (rather than capturing events which I'm currently not doing:) ) is how one would go about build an app that features both windowed and full screen exclusive support ?

I assume I would have to hard code this for each case. (ie. use canvas/windowed or use graphics for full screen exclusive..) But I'm hoping there's a more intuitive way however.

yep newbie alert..


CS_TBL(Posted 2003) [#2]
and I'd like to add a subject to this question:

fullscreen on *my* 17" TFT monitor means 1280x1024, a 5:4 aspect ratio. A normal CRT usually has a 4:3 aspect ratio. Since I prefer real squares (1:1), it'd be fine it ppl included this knowledge, by centralising their output. Basicly meaning 2 black bars at the top and bottom.. just like widescreenmovies on your 4:3 TV.

I spent some time on this myself, nothing special, but my output window runs perfect on all resolutions.


uwdesign(Posted 2003) [#3]
So, does anybody know the right way to build app's supporting both Full Screen and windowed mode ?.


EOF(Posted 2003) [#4]
You can still use the Graphics command for windowed mode without having to use canvases etc...
Use a value of '2' for the flags:

fullscreen=False

sw=400 : sh=300 : videomode=2
If fullscreen=True Then sw=640 : sh=480 : videomode=1

Graphics sw,sh,0,videomode
SetBuffer BackBuffer()

Repeat
	Cls
	Rect Rand(sw),Rand(sh),Rand(100),Rand(100)
	Flip
Until KeyHit(1)

End



soja(Posted 2003) [#5]
I wrote a game with an earlier version of BlitzPlus (earlier than 1.35). I wanted to have a fullscreen mode and a true windowed mode (i.e. with Windows menus, etc). The program involves using a canvas in windowed mode, and using a Graphics window in fullscreen mode. When switching between modes, it destroys the previous interface (graphics or canvas) as it creates the new interface.

It worked pretty well then, however when I try it now, it doesn't work. I've discovered that it's due to the changes that Mark put in regarding Canvases and Graphics -- trying to make BlitzPlus code more compatible with Blitz2D. It doesn't allow a canvas to be shown after calling EndGraphics. (I figure it's a bug, but perhaps it's by some design that I don't understand. If so, please tell me. At any rate I file a bug report.)

Here's the code I used. Note that I added in HotKey events just now, and took out most of the code that doesn't apply to this example. Pay most attention to InitDisplay() and SwapDisplay().

Note also that the drawing (client) area of the two screens are exactly the same. This makes it so that you don't have to change any of your drawing code, which is a nice plus.

Comment out the EndGraphics command to get a glimpse of what the action should be like. (It will just create multiple windows.)

;------------------------------
; CONSTS

Const evKeystroke		= $103
Const evWindowClose 	= $803
Const evTimerTick 		= $4001
Const evSwapDisplay		= $99 ; Custom event for Hotkey F11

Const WNDWIDTH	= 800
Const WNDHEIGHT	= 600

;------------------------------
; GLOBALS

Global WndMain, CanMain, TimerDraw
Global bWindowed = True ; True = windowed mode, False = fullscreen mode

;------------------------------
; MAIN_LOOP()
	
InitGame()
InitDisplay() 

While WaitEvent()
	Select EventID()
		Case evTimerTick : Draw()
		Case evWindowClose : End
		Case evSwapDisplay : SwapDisplay() ; Hotkey F11
	End Select
Wend

;------------------------------
; FUNCTIONS

Function InitGame()
	CreateTimer(60)
	HotKeyEvent 87, 0, evSwapDisplay ; Hotkey F11
	HotKeyEvent 1, 0, evWindowClose ; Hotkey ESC
End Function

Function InitDisplay()
	If bWindowed Then 
		; Set up Windowed mode (having the same client area as Fullscreen window)
		Local x% = (ClientWidth(Desktop()) - WNDWIDTH) / 2
		Local y% = (ClientHeight(Desktop()) - WNDHEIGHT) / 2
		WndMain = CreateWindow("Window (windowed mode)", x, y, WNDWIDTH, WNDHEIGHT, 0, 47)
		CanMain = CreateCanvas(0, 0, ClientWidth(WndMain), ClientHeight(WndMain), WndMain)
		SetGadgetLayout(CanMain, 1, 2, 1, 2)
		SetBuffer CanvasBuffer(CanMain)
	Else 
		; Set up Fullscreen mode
		AppTitle("Window (fullscreen mode)")
		Graphics(WNDWIDTH, WNDHEIGHT)
		SetBuffer(BackBuffer())
	EndIf
End Function

Function SwapDisplay()
	If bWindowed Then 
		; Switch to Fullscreen mode
		bWindowed = False 
		FreeGadget WndMain
	Else
		; Switch to Windowed mode
		bWindowed = True
		EndGraphics ; <--- Has problem in v1.35 -- can't create canvas after this call
	End If
	InitDisplay()
End Function

Function Draw()
	Color Rand(255), Rand(255), Rand(255)
	Rect Rand(WNDWIDTH), Rand(WNDHEIGHT), Rand(WNDWIDTH/2), Rand(WNDHEIGHT/2), True
	If bWindowed Then FlipCanvas CanMain Else Flip
End Function



uwdesign(Posted 2003) [#6]
Syntax Error,

Thanks, I'm currently using the windows toggle with graphics. I just figured It'd be better to create a window/menus when in windowed mode.. So was looking for if there was built in way to support swapping modes. I guess not .. oh well..



Soja,

Thank you, you've been very helpful. I had figured i'd have to handle it as your example does. It's a pity that issue with endgraphics exists. I guess i'll have to stick with graphics windowed mode for now then.

Ironically when graphics is set to windowed mode apptitle no longer takes effect. Is this expected behavior ? Actually the window has no controls anymore either.. oh well