I´m trying to create a small program that can handle a 3D screen in different ways. One problem I have is that if I have an opened 3D screen, add the basic 3D stuff(light, mesh, camera) closes it, and then creates the same screen again, the program crashes. So I need help in figuring out(if possible) how to solve this.
The code below creates a 3D screen and displays a cube. If the users hits "F" I want it to close the screen and then create it again.
Or if the user hits "ALT+TAB" it closes the screen, creates a small window and waits for input. If the users then either TABs back to the program(to the small window) or clicks on it in the active programs list, the small window closes and then creates the screen.
The problem seems to be with the reinitialization of the basic 3D stuff. I have tried to free them up before I close the screen but that doesn´t help. My guess is that something else needs to be done for the new screen to be created properly. My fear is that this is an OGRE issue and can´t be solved. But I have faith in this forum
Can anyone solve this for me?
Code: Select all
InitEngine3D()
InitSprite()
InitKeyboard()
ExamineDesktops()
OpenScreen(DesktopWidth(0), DesktopHeight(0), DesktopDepth(0),"3D Test",#PB_Screen_NoSynchronization, DesktopFrequency(0))
AmbientColor(RGB(80, 80, 100))
WorldShadows(#PB_Shadow_Additive)
mesh=CreateCube(#PB_Any,20)
CreateEntity(0, MeshID(mesh), #PB_Material_None)
RotateEntity(0,35,15,0)
light_Sun=CreateLight(#PB_Any, RGB(201, 226, 255), 0, 3000, 0)
cam_Main=CreateCamera(#PB_Any, 0, 0, 100, 100)
MoveCamera(cam_Main,0,0,50)
CameraRange(cam_Main, 0, 5000)
CameraFOV(cam_Main, 90)
CameraBackColor(cam_Main, RGB(70, 100, 182))
Repeat
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Escape) ;quit the program
End
ElseIf KeyboardReleased(#PB_Key_F)
CloseScreen()
OpenScreen(DesktopWidth(0), DesktopHeight(0), DesktopDepth(0),"3D Test",#PB_Screen_NoSynchronization, DesktopFrequency(0))
AmbientColor(RGB(80, 80, 100))
WorldShadows(#PB_Shadow_Additive)
mesh=CreateCube(#PB_Any,20)
CreateEntity(0, MeshID(mesh), #PB_Material_None)
RotateEntity(0,35,15,0)
light_Sun=CreateLight(#PB_Any, RGB(201, 226, 255), 0, 3000, 0)
cam_Main=CreateCamera(#PB_Any, 0, 0, 100, 100)
MoveCamera(cam_Main,0,0,50)
CameraRange(cam_Main, 0, 5000)
CameraFOV(cam_Main, 90)
CameraBackColor(cam_Main, RGB(70, 100, 182))
EndIf
If KeyboardPushed(#PB_Key_LeftAlt)
If KeyboardPushed(#PB_Key_Tab)
CloseScreen()
OpenWindow(1,1,1,1,1, "3D Test" , #PB_Window_Minimize )
Repeat
Event= WaitWindowEvent(2)
Until Event= #PB_Event_ActivateWindow
CloseWindow(1)
OpenScreen(DesktopWidth(0), DesktopHeight(0), DesktopDepth(0),"3D Test",#PB_Screen_NoSynchronization, DesktopFrequency(0))
AmbientColor(RGB(80, 80, 100))
WorldShadows(#PB_Shadow_Additive)
mesh=CreateCube(#PB_Any,20)
CreateEntity(0, MeshID(mesh), #PB_Material_None)
RotateEntity(0,35,15,0)
light_Sun=CreateLight(#PB_Any, RGB(201, 226, 255), 0, 3000, 0)
cam_Main=CreateCamera(#PB_Any, 0, 0, 100, 100)
MoveCamera(cam_Main,0,0,50)
CameraRange(cam_Main, 0, 5000)
CameraFOV(cam_Main, 90)
CameraBackColor(cam_Main, RGB(70, 100, 182))
EndIf
EndIf
RenderWorld()
FlipBuffers()
ForEver