Page 1 of 1

InitEngine3d() -> ReInitEngine3d() ?

Posted: Tue Nov 09, 2004 4:44 am
by JonChaos
hi
i would like to know if there is a way to re initialise the 3d engine
because as soon as a fullscreen 3d app is minimised and thereafter reactivated the app crashes

first i thougt there is a way to reload resources or such like the problem with reactivating fullscreen apps using sprites

but i havent foundt a solution/workaround for the problem with initengine3d()

Posted: Tue Nov 09, 2004 5:45 pm
by thefool
you should make the program HALT if the window is not the active one.

Posted: Wed Nov 10, 2004 6:20 pm
by JonChaos
sorry but that hasnt worked

i tried with

Code: Select all

Repeat 
    WaitWindowEvent() 
Until IsScreenActive()<>0 
and some delay functions but the result is always the same
crash on return to the app

Posted: Thu Nov 11, 2004 9:56 am
by dige
May be that works

Code: Select all

#hWnd = 0

InitSprite()

OpenWindow(#hWnd, 10, 10, 800, 600, #PB_Window_SystemMenu,  "Test")
OpenWindowedScreen(WindowID(), 200, 200, 400, 300, 0, 0, 0)

Repeat
  If IsScreenActive() And GetActiveWindow_() = WindowID(#hWnd)
    FlipBuffers()
    ClearScreen(0,0,0)
  EndIf
Until WindowEvent() = #PB_EventCloseWindow
cya dige

Re: InitEngine3d() -> ReInitEngine3d() ?

Posted: Mon Nov 15, 2004 1:24 am
by JonChaos
thx but that is not the kind of solution im serchin for
because as soon as a fullscreen 3d app is minimised and thereafter reactivated the app crashes

Posted: Wed Nov 17, 2004 10:16 pm
by JonChaos
i played a bit with ogre in c++ and i noticed the same behaviour

is there a workaround known or a fix in work ?

otherwise i have to switch back to c++ which means a lot more work than writin in pb

Posted: Thu Nov 18, 2004 10:25 am
by dige
You should post your code here. Maybe there is something wrong.
I have coded with ogre a 3D city modell with more than 2Mio triangels,
livecam billboards, flood simulation etc...
And everything works fine.

Image

No problem to minimize and restore the screen/window ...

cya dige

Posted: Sat Nov 20, 2004 5:18 pm
by JonChaos
even if u start it fullscreen
then hit alt-tab to switch to the desktop
and then restore the app

?

Posted: Sun Nov 21, 2004 11:59 pm
by JonChaos
here is the code

Code: Select all

InitEngine3D()
InitSprite()
InitKeyboard()

#CameraSpeed = 5

  DefType.f KeyX, KeyY
  
  Add3DArchive("Data\"          , #PB_3DArchive_FileSystem)
 
  If OpenScreen(1024, 768, 16, "Test") <> 0

    AmbientColor(RGB(255,255,255))
    
    CreateMaterial  (0, LoadTexture(0, "Terrain_Texture.jpg"))
    AddMaterialLayer(0, LoadTexture(1, "Terrain_Detail.jpg"), 1)
    
    CreateTerrain("Terrain.png", MaterialID(0), 4, 0.6, 4, 4)

    CreateCamera(0, 0, 0, 100, 100)
    CameraLocate(0, 128, 25, 128)
        
    Repeat
            
      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
            
      Height.f = TerrainHeight(CameraX(0), CameraZ(0))
      
      RotateCamera(0, MouseX, MouseY, RollZ)
      MoveCamera  (0, KeyX, -CameraY(0)+Height+8, KeyY)
            
      RenderWorld()
              
      If StartDrawing(ScreenOutput())
      FrontColor(255, 255, 255)
      DrawingMode(1)
      Locate(50, 50)  : DrawText(StrF(Engine3DFrameRate(0),1)+" FPS")
      Locate(50, 70) : DrawText(Str(CountRenderedTriangles())+" Triangles")
      StopDrawing()
      EndIf
      
      FlipBuffers()
    Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
  EndIf    
End
i tried to pause the app while the window isnt active but that didnt solve the problem

Posted: Mon Nov 22, 2004 9:08 am
by traumatic
First of all, I never really used OGRE but on the other hand it also
shouldn't be different than anything else because due to the nature
of multitasking enviornments like Windows, you should always check
whether your window receives messages or not.

I think you'll have to check if your application is 'active' at all.

Dige already suggested you to do it like this:

Code: Select all

If IsScreenActive() And GetActiveWindow_() = WindowID(#hWnd) 
[...]
Did you try that?

Posted: Tue Nov 23, 2004 5:03 am
by JonChaos
Did you try that?
yes i have
and i know that everybody else who tried to help hasnt cause pausing the main loop while the window isnt active doesnt change the behaviour of the program
but thx anyway

Posted: Tue Nov 23, 2004 7:18 pm
by traumatic
Well, now I tried it myself...

Using IsScreenActive() helps to prevent the app from crashing
but I just didn't manage to get the app on focus again...

I searched this and the german forum seeing that quite a lot of people
reported this behaviour. (I even found another thread of yours ;))

Either we all don't understand the concept or there's a bug somewhere.
Seems like Fred has already been informed but didn't answer so far.

Using plain Direct3D (ie no OGRE) I'd do it like this:

Code: Select all

procedure IsDeviceActive()
  select d3dDevice\TestCooperativeLevel()
    case #D3DERR_DEVICELOST
      procedurereturn #FALSE
   
    case #D3DERR_DEVICENOTRESET
  
    if d3dDevice\Reset(@PresentParameters) <> #D3D_OK
      procedurereturn #FALSE
      
    else
      ; re-init scene here
      ; (ie. re-create all textures, vertex or index buffers
      ; initially created with #D3DPOOL_DEFAULT.
      ; We also lost the projection matrix and renderstates)
      
      ;
      
      ; done re-init
      procedurereturn #TRUE
    endif

    default
      procedurereturn #TRUE
  endselect
endprocedure
But AFAIK there's no PB-command that returns the necessary deviceinfo.


Fred? Can you shed light on this?

Posted: Fri Dec 03, 2004 3:19 pm
by JonChaos
hmm
seems like this part of pb is not important enough to be discussed or fixed :(

Posted: Sat Dec 25, 2004 2:56 pm
by JonChaos
bump