Page 1 of 1

How to manage FullScreen+ALT TAB

Posted: Sun Jul 13, 2008 1:43 pm
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 

Posted: Tue Jul 22, 2008 1:05 pm
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 

Posted: Tue Jul 22, 2008 8:00 pm
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

Posted: Tue Jul 22, 2008 10:16 pm
by djes
I've answered on the bug thread to not "pollute" this one. If you want I can delete my post...