[PB5.03 beta x86] Alt-Tab in 3D does not work

All bugs related to the 3D engine
Hoessi666
User
User
Posts: 24
Joined: Fri Feb 05, 2010 6:44 pm

[PB5.03 beta x86] Alt-Tab in 3D does not work

Post by Hoessi666 »

Alt-Tabbing between a 3D-Application and other Programs doesn´t work. The 3D-Apllication stays in the Foreground and it´s hard to end it because you don´t know when it´s active in the Computer-Environement and when not...

A little Example:

Code: Select all

InitEngine3D()
InitSprite()
InitMouse()
InitKeyboard()

Global Now.l, FrameDuration.w
Global Stats.i, Camera.i

Procedure DrawStats()
  
  StartDrawing(SpriteOutput(Stats))
    DrawText(0, 0, "FpS: "+Str(Engine3DFrameRate(#PB_Engine3D_Current)))
    DrawText(0,20, "Duration: "+Str(FrameDuration))
    DrawText(0,40, "Pos.: "+StrF(CameraX(Camera),2)+"/"+StrF(CameraY(Camera),2)+"/"+StrF(CameraZ(Camera),2))
  StopDrawing()
  
  DisplaySprite(Stats, 0,0)
  
EndProcedure

OpenScreen(1024,768,32, "3DTry")

Camera=CreateCamera(#PB_Any, 0,0, 100,100)
CameraLocate(Camera, 0, 0.75, 1)
CameraLookAt(Camera, 0, 0.75, 0)

Stats=CreateSprite(#PB_Any, 256, 70)


CreateTexture(0, 256,256)
StartDrawing(TextureOutput(0))
  Box(0,0,256,2586,RGB(0,0,255))
StopDrawing()
  
CreateMaterial(0, TextureID(0))  

CreateCube(0,1)
CreateEntity(0, MeshID(0), MaterialID(0),0,0,0)


Now=ElapsedMilliseconds()

Repeat
  
  ;{ Keys
  ExamineKeyboard()
  
  If KeyboardPushed(#PB_Key_Up)
    MoveCamera(Camera, 0,0,-0.1)
  ElseIf KeyboardPushed(#PB_Key_Down)
    MoveCamera(Camera, 0,0,0.1)
  EndIf
  
  If KeyboardPushed(#PB_Key_Left)
    MoveCamera(Camera, -0.1,0,0)
  ElseIf KeyboardPushed(#PB_Key_Right)
    MoveCamera(Camera, 0.1,0,0)
  EndIf
  
  If KeyboardPushed(#PB_Key_PageUp)
    MoveCamera(Camera, 0,0.1,0)
  ElseIf KeyboardPushed(#PB_Key_PageDown)
    MoveCamera(Camera, 0,-0.1,0)
  EndIf
  
  If KeyboardPushed(#PB_Key_Escape)
    CloseScreen()
    End
  EndIf
  ;}
  
  
  ;{ Stats und show Screen
  If IsScreenActive()=0
    CloseScreen()
    End
  EndIf
  
  RenderWorld()
  
  OldNow=Now
  Now=ElapsedMilliseconds()
  FrameDuration=Now-OldNow
  DrawStats()
  
  FlipBuffers()
  ;}
  
ForEver

User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Re: [PB5.03 beta x86] Alt-Tab in 3D does not work

Post by djes »

Please do a search in forum before posting...
Hoessi666
User
User
Posts: 24
Joined: Fri Feb 05, 2010 6:44 pm

Re: [PB5.03 beta x86] Alt-Tab in 3D does not work

Post by Hoessi666 »

djes wrote:Please do a search in forum before posting...
Sorry, I only found Stuff concerning 2D-based Games, when the Screen loses its focus... That Problem is solved with proper programming techniques...
This here is different , ´cause you can´t even leave the Screen (at least on my Computer :lol: )

If there´s already a thread about this here, I haven´t seen it and then: Sorry! :(
PMV
Enthusiast
Enthusiast
Posts: 727
Joined: Sat Feb 24, 2007 3:15 pm
Location: Germany

Re: [PB5.03 beta x86] Alt-Tab in 3D does not work

Post by PMV »

It is still present in v5.20 Beta 10 and i already see many
bug-reports by my imaginary gamers. :lol:
it is impossible to go back to desktop while running.

This is the CreateTexture.pb example with addition IsScreenActive()
Just select fullscreen in the settings-menu.

Code: Select all

;
; ------------------------------------------------------------
;
;   PureBasic - CreateTexture
;
;    (c) 2011 - Fantaisie Software
;
; ------------------------------------------------------------
;

; one load function to be called at start up and after device lost
Procedure LoadResource()
  ReleaseMouse(#False)
  
  ; Texture
  ;
  CreateTexture(0, 256, 256)
  StartDrawing(TextureOutput(0))
    Box(0, 0, 256, 256, RGB(90, 40, 0))
    Box(6, 6, 244, 244, RGB(190, 140, 0))
    DrawingMode(#PB_2DDrawing_Transparent)
    DrawingFont(FontID(0))
    DrawText(10, 110, "PureBasic", RGB(90, 40, 90))
  StopDrawing()
  
  CreateMaterial(0, TextureID(0))
  
  ; Cube
  ;
  CreateCube(0, 30)
  CreateEntity(0, MeshID(0), MaterialID(0))  
EndProcedure

#CameraSpeed = 1

IncludeFile "Screen3DRequester.pb"

Define.f KeyX, KeyY, MouseX, MouseY

LoadFont(0, "Arial", 28, #PB_Font_Bold)

If InitEngine3D()
  
  Add3DArchive("Data/Textures", #PB_3DArchive_FileSystem)
  Add3DArchive("Data/Models", #PB_3DArchive_FileSystem)
  
  InitSprite()
  InitKeyboard()
  InitMouse()
  
  If Screen3DRequester()
    
    AmbientColor(RGB(255,255,255))
    
    LoadResource()
    
    
    CreateCamera(0, 0, 0, 100, 100)
    MoveCamera(0, 0, 0, 100, #PB_Absolute)
    
    Repeat
      FlipBuffers()
      Screen3DEvents()
      
      If ExamineMouse()
        MouseX = -MouseDeltaX() * #CameraSpeed * 0.05
        MouseY = -MouseDeltaY() * #CameraSpeed * 0.05
      EndIf
      
      If ExamineKeyboard()
        
        If KeyboardPushed(#PB_Key_Left)
          KeyX = -#CameraSpeed 
        ElseIf KeyboardPushed(#PB_Key_Right)
          KeyX = #CameraSpeed 
        Else
          KeyX = 0
        EndIf
        
        If KeyboardPushed(#PB_Key_Up)
          KeyY = -#CameraSpeed 
        ElseIf KeyboardPushed(#PB_Key_Down)
          KeyY = #CameraSpeed 
        Else
          KeyY = 0
        EndIf
        
      EndIf
            
      If IsScreenActive()
        If ScreenActive = #False
          Debug "Screen activated"
          LoadResource()
        EndIf
        ScreenActive = #True
        RotateEntity(0, 0, 1, 0, #PB_Relative)
        
        RotateCamera(0, MouseY, MouseX, 0, #PB_Relative)
        MoveCamera  (0, KeyX, 0, KeyY)
        
        RenderWorld()
        
        Screen3DStats()
      ElseIf ScreenActive
        ReleaseMouse(#True)
        ScreenActive = #False
        Debug "Screen is inactive"
      EndIf

    Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
  EndIf
  
Else
  MessageRequester("Error", "The 3D Engine can't be initialized",0)
EndIf

End
The Debug-Line will never be printed and it is impossible
to left the screen. Gamers really love that behavior.
Declines all the good new PB-OGRE functions. :x
There seems a lazy solution for smaller 3d applications:
D3DPOOL_MANAGED ... if resources are loaded with that,
DX9 will copy the video-memory data to system-
memory and so on device lost it restores the resource
themself. Would be really nice to have such a possibility
for PB, as the most people will just create small games.
Of course, this should be just optional. :)

When losing device, PB already knows all allocated objects stored
in video-memory? Does PB already clean up all video-memory-data
on device-lost? If not ... this is an additional bug as only then
IDirect3DDevice9::Reset can be called to restore the device.
And only then it is possible to reload all data into video-memory.

PS: the thread-safe bug could be related to this one, too:
http://www.purebasic.fr/english/viewtop ... =4&t=35669 :)

MFG PMV


Edit: The topic in MSDN, if someone else wants to read it:
http://msdn.microsoft.com/en-us/library ... s.85).aspx
PMV
Enthusiast
Enthusiast
Posts: 727
Joined: Sat Feb 24, 2007 3:15 pm
Location: Germany

Re: [PB5.03 beta x86] Alt-Tab in 3D does not work

Post by PMV »

I have found something "new" ... as with Vista, DirectX
doesn't looses the device any longer that easily ...
http://msdn.microsoft.com/en-us/library ... s.85).aspx
Device Behavior Changes

Devices are now only lost under two circumstances; when the hardware is reset because it is hanging, and when the device driver is stopped. When hardware hangs, the device can be reset by calling ResetEx. If hardware hangs, texture memory is lost.
Don't know, if there is something needed to be done, to support
that, ... but this should make the alt+tab problem much easier
for all of us. Even so you still want to support XP and earlier,
it will need a function where we can get the information
1. if fullscreen has lost focus
2. if fullscreen has gained focus
3. if all resource needs to be reloaded after 2.
And additional freeing the resource to reset the device-state
after lost, preferably by PB them self.

:idea: Maybe D3DPOOL_MANAGED should then be used per default
if it is not Vista (and a WDDM supported driver)

Enough research of this topic for today :mrgreen:
Hope this information is helpful :)

MFG PMV
mrw
User
User
Posts: 76
Joined: Wed Dec 31, 2014 1:01 pm

Re: [PB5.03 beta x86] Alt-Tab in 3D does not work

Post by mrw »

Sorry for bumping a 4 year old thread, but I couldn´t find any more recent and this topic is exactly my problem.
Is this still not fixed, or has noone come up with a workaround? Now using version 5.60 x64.

The problem exists though.
If I create a Fullscreen, using OpenScreen(), after I have run InitEngine3D() it´s not possible to ALT-TAB back to Windows.

If I skip the InitEngine3D() I can ALT-TAB back to Windows, and with a little code-handling I can have it ALT-TAB back.
But this does not work at all with InitEngine3D() since nothing happens when I hit ALT-TAB.

What can be done?

//Andreas..
Post Reply