How to manage FullScreen+ALT TAB

Share your advanced PureBasic knowledge/code with the community.
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

How to manage FullScreen+ALT TAB

Post by eddy »

Code: Select all

CompilerIf Defined(D3DBLEND_ZERO, #PB_Constant)=0
   #D3DBLEND_ZERO=1
   #D3DBLEND_ONE=2
   #D3DBLEND_SRCCOLOR=3
   #D3DBLEND_INVSRCCOLOR=4
   #D3DBLEND_SRCALPHA=5
   #D3DBLEND_INVSRCALPHA=6
   #D3DBLEND_DESTALPHA=7
   #D3DBLEND_INVDESTALPHA=8
   #D3DBLEND_DESTCOLOR=9
   #D3DBLEND_INVDESTCOLOR=10
   #D3DBLEND_SRCALPHASAT=11
   #D3DBLEND_BOTHSRCALPHA=12
   #D3DBLEND_BOTHINVSRCALPHA=13
CompilerEndIf

InitSprite()
InitSprite3D()
InitKeyboard()
InitMouse()
OpenScreen(1024, 768, 32, "Custom PB Sprite3D")

CreateSprite(1, 256, 256, #PB_Sprite_Texture)
StartDrawing(SpriteOutput(1))
   Box(0, 0, 256, 256, RGB(255, 200, 100))
   Box(0, 0, 50, 50, $FFFFFF ! RGB(255, 200, 100))
   Box(50, 50, 50, 50, $FFFFFF ! RGB(255, 200, 100))
   Box(236, 0, 20, 256, RGB(161, 87, 177))
StopDrawing()

Sprite3DQuality(#PB_Sprite3D_BilinearFiltering)
CreateSprite3D(1, 1)
CreateSprite3D(2, 1)
CreateSprite3D(3, 1)

ZoomSprite3D(1, 256, 256)
ZoomSprite3D(2, 128, 128)
ZoomSprite3D(3, 64, 64)

Procedure DoScreenDisplay()
   ExamineKeyboard()
   ExamineMouse()
   Protected x=MouseX()
   Protected y=MouseY()
   
   ClearScreen(RGB(0, 0, 0))
   Start3D()
      Sprite3DBlendingMode(#D3DBLEND_SRCALPHA, #D3DBLEND_INVSRCALPHA)
      DisplaySprite3D(1, 100, 200)
      
      Sprite3DBlendingMode(#D3DBLEND_INVDESTCOLOR, #D3DBLEND_SRCALPHA)
      RotateSprite3D(2, 1, 1)
      For pos=3 To 8
         DisplaySprite3D(2, pos*60, 290)
      Next 
      
      Sprite3DBlendingMode(#D3DBLEND_SRCALPHA, #D3DBLEND_INVSRCALPHA)
      DisplaySprite3D(3, x, y, 100)
      
   Stop3D()   
   FlipBuffers()
EndProcedure

Procedure GoBackToOS()
   ReleaseMouse(1)
   Repeat
      FlipBuffers()
   Until IsScreenActive()
   ReleaseMouse(0)
EndProcedure

Repeat
   DoScreenDisplay()
   
   ;/// Manage ALT TAB
   If Not IsScreenActive()
      GoBackToOS()
   EndIf
Until KeyboardPushed(#PB_Key_Escape)

CloseScreen()
End 
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Post by djes »

Try with this code to do ALT-TAB and going back : crash!

Code: Select all

CompilerIf Defined(D3DBLEND_ZERO, #PB_Constant)=0
   #D3DBLEND_ZERO=1
   #D3DBLEND_ONE=2
   #D3DBLEND_SRCCOLOR=3
   #D3DBLEND_INVSRCCOLOR=4
   #D3DBLEND_SRCALPHA=5
   #D3DBLEND_INVSRCALPHA=6
   #D3DBLEND_DESTALPHA=7
   #D3DBLEND_INVDESTALPHA=8
   #D3DBLEND_DESTCOLOR=9
   #D3DBLEND_INVDESTCOLOR=10
   #D3DBLEND_SRCALPHASAT=11
   #D3DBLEND_BOTHSRCALPHA=12
   #D3DBLEND_BOTHINVSRCALPHA=13
CompilerEndIf

InitEngine3D() ;<- Guilty!
InitSprite()
InitSprite3D()
InitKeyboard()
InitMouse()
OpenScreen(1024, 768, 32, "Custom PB Sprite3D")

CreateSprite(1, 256, 256, #PB_Sprite_Texture)
StartDrawing(SpriteOutput(1))
   Box(0, 0, 256, 256, RGB(255, 200, 100))
   Box(0, 0, 50, 50, $FFFFFF ! RGB(255, 200, 100))
   Box(50, 50, 50, 50, $FFFFFF ! RGB(255, 200, 100))
   Box(236, 0, 20, 256, RGB(161, 87, 177))
StopDrawing()

Sprite3DQuality(#PB_Sprite3D_BilinearFiltering)
CreateSprite3D(1, 1)
CreateSprite3D(2, 1)
CreateSprite3D(3, 1)

ZoomSprite3D(1, 256, 256)
ZoomSprite3D(2, 128, 128)
ZoomSprite3D(3, 64, 64)

Procedure DoScreenDisplay()
   ExamineKeyboard()
   ExamineMouse()
   Protected x=MouseX()
   Protected y=MouseY()
   
   ClearScreen(RGB(0, 0, 0))
   Start3D()
      Sprite3DBlendingMode(#D3DBLEND_SRCALPHA, #D3DBLEND_INVSRCALPHA)
      DisplaySprite3D(1, 100, 200)
     
      Sprite3DBlendingMode(#D3DBLEND_INVDESTCOLOR, #D3DBLEND_SRCALPHA)
      RotateSprite3D(2, 1, 1)
      For pos=3 To 8
         DisplaySprite3D(2, pos*60, 290)
      Next
     
      Sprite3DBlendingMode(#D3DBLEND_SRCALPHA, #D3DBLEND_INVSRCALPHA)
      DisplaySprite3D(3, x, y, 100)
     
   Stop3D()   
   FlipBuffers()
EndProcedure

Procedure GoBackToOS()
   ReleaseMouse(1)
   Repeat
      FlipBuffers()
   Until IsScreenActive()
   ReleaseMouse(0)
EndProcedure

Repeat
   DoScreenDisplay()
   
   ;/// Manage ALT TAB
   If Not IsScreenActive()
      GoBackToOS()
   EndIf
Until KeyboardPushed(#PB_Key_Escape)

CloseScreen()
End 
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Post by eddy »

Perhaps a bug ?

:idea: I've found the reason ... Sprite3D and Engine3D are not fully compatible
Syntax

RenderWorld()
Description

Renders the whole world on the screen. This function should be called once all 3D operations are finished and only one time per frame.

Once the RenderWorld() function has been performed, it's possible to use regular 2D functions like DisplaySprite() to display 2D sprites over the 3D world (note: Sprite3D is not supported though).

Code: Select all

CompilerIf Defined(D3DBLEND_ZERO, #PB_Constant)=0
   #D3DBLEND_ZERO=1
   #D3DBLEND_ONE=2
   #D3DBLEND_SRCCOLOR=3
   #D3DBLEND_INVSRCCOLOR=4
   #D3DBLEND_SRCALPHA=5
   #D3DBLEND_INVSRCALPHA=6
   #D3DBLEND_DESTALPHA=7
   #D3DBLEND_INVDESTALPHA=8
   #D3DBLEND_DESTCOLOR=9
   #D3DBLEND_INVDESTCOLOR=10
   #D3DBLEND_SRCALPHASAT=11
   #D3DBLEND_BOTHSRCALPHA=12
   #D3DBLEND_BOTHINVSRCALPHA=13
CompilerEndIf

InitEngine3D()
InitSprite()
; InitSprite3D() ;<- Guilty!
InitKeyboard()
InitMouse()
OpenScreen(1024, 768, 32, "Custom PB Sprite3D")

CreateSprite(1, 256, 256, #PB_Sprite_Texture)
StartDrawing(SpriteOutput(1))
   Box(0, 0, 256, 256, RGB(255, 200, 100))
   Box(0, 0, 50, 50, $FFFFFF ! RGB(255, 200, 100))
   Box(50, 50, 50, 50, $FFFFFF ! RGB(255, 200, 100))
   Box(236, 0, 20, 256, RGB(161, 87, 177))
StopDrawing()

; Sprite3DQuality(#PB_Sprite3D_BilinearFiltering)
; CreateSprite3D(1, 1)
; CreateSprite3D(2, 1)
; CreateSprite3D(3, 1)
;
; ZoomSprite3D(1, 256, 256)
; ZoomSprite3D(2, 128, 128)
; ZoomSprite3D(3, 64, 64)

Procedure DoScreenDisplay()
   ExamineKeyboard()
   ExamineMouse()
   Protected x=MouseX()
   Protected y=MouseY()
   
   ClearScreen(RGB(0, 0, 0))
   ;    Start3D()
   ;       Sprite3DBlendingMode(#D3DBLEND_SRCALPHA, #D3DBLEND_INVSRCALPHA)
   ;       DisplaySprite3D(1, 100, 200)
   ;
   ;       Sprite3DBlendingMode(#D3DBLEND_INVDESTCOLOR, #D3DBLEND_SRCALPHA)
   ;       RotateSprite3D(2, 1, 1)
   ;       For pos=3 To 8
   ;          DisplaySprite3D(2, pos*60, 290)
   ;       Next
   ;
   ;       Sprite3DBlendingMode(#D3DBLEND_SRCALPHA, #D3DBLEND_INVSRCALPHA)
   ;       DisplaySprite3D(3, x, y, 100)
   ;
   ;    Stop3D()
   
   RenderWorld()
   FlipBuffers()
   
EndProcedure

Procedure GoBackToOS()
   ReleaseMouse(1)
   Repeat
      FlipBuffers()
   Until IsScreenActive()
   ReleaseMouse(0)
EndProcedure

Repeat
   DoScreenDisplay()
   
   ;/// Manage ALT TAB
   If Not IsScreenActive()
      GoBackToOS()
   EndIf
Until KeyboardPushed(#PB_Key_Escape)

CloseScreen()
End
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Post by djes »

I've answered on the bug thread to not "pollute" this one. If you want I can delete my post...
Post Reply