OGRE in second window?

Everything related to 3D programming
Didaktik
User
User
Posts: 79
Joined: Fri Mar 14, 2014 2:12 pm

OGRE in second window?

Post by Didaktik »

I want to make two windows. In a normal windows gui. In the second screen with Ogre 3D.

How to handle events from the two windows? I have a second window has a white screen and there is no picture and no error messages.

The second window need to open with the parameter "Parent Window"?

Main loop:

Code: Select all


  Init3D()

  Repeat
    
    Repeat
      event = WindowEvent()
      
      
      
      Select event
          
        Case #PB_Event_CloseWindow
          
          Quit = 1
          
        Case #WM_MOUSEWHEEL: FxMouseWheel()
          
      EndSelect
      
    Until event = 0
    
    SetGadgetText3D(2,"FPS: "+StrF(Engine3DStatus(#PB_Engine3D_Current),2))
    
CubesGlobal()
  RenderWorld()
  
  x = WindowMouseX(1) - (DesktopWidth(0)-560)
  y = WindowMouseY(1) - (#Canvas_settings_height+#margin)
  
  DisplayTransparentSprite(1, x, y, 255)
  FlipBuffers()

    
  Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1 

User avatar
Bananenfreak
Enthusiast
Enthusiast
Posts: 519
Joined: Mon Apr 15, 2013 12:22 pm

Re: OGRE in second window?

Post by Bananenfreak »

Hi Didaktik,

Code: Select all

SetGadgetText3D(2,"FPS: "+StrF(Engine3DStatus(#PB_Engine3D_Current),2))
will only work with a 3D-Window (CEGUI).

You can handle the Windowevents normal, like always.
But you have to ask which window generated the Event:

Code: Select all

    Repeat
      event = WindowEvent()
      
      
      
      Select event
          
        Case #PB_Event_CloseWindow
          select EventWindow()
             case #Window_1
               debug "Window 1 closed
               Quit = 1

              case #Window_2
                      .....

          Endselect
          
        Case #WM_MOUSEWHEEL: FxMouseWheel()
          
      EndSelect
      
    Until event = 0
If you want your Windows parallel, you´ll have no need to handle one of These Windows as Parentwindow.
If you want one window in front of another (always) and you want to minimize all Windows by minimizing the parent window, you´ll have to use one window as parentwindow.
Image
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: OGRE in second window?

Post by applePi »

i never tried multiple windows , but i want to test Bananenfreak idea such as closing a specific window from multiple windows.
in window #winOne click on RunMe Button, and it will open another window #winTwo which contains the graphics. now close this second window to return to the first window. and click RunMe again, i get memory access error in line OpenWindowedScreen(...) inside the windowTwo procedure.
i know there is no need for such an unnecessary pushing the things. but just have a curiosity if there is a solution to this specific case .
PS: i choose drawing irrelevant fractal shape just as a change to the usual sphere/cube may someone find it funny
PS_2: PS: I have added CloseScreen() to the end of WindowTwo() procedure, and adding
InitEngine3D()
InitSprite()
after Button_1 click
still the same error in line OpenWindowedScreen(...) inside the windowTwo procedure.

Code: Select all

Enumeration
   #MESH
   #TEX_plane
   #MAT
   #MAT_plane
   #plane
   #LIGHT
   #CAMERA
   #BUTTON_1
   #BUTTON_2
   #TextBox
   #winOne
   #winTwo
 EndEnumeration
 #constreal = 0.5 
  #constimag = 0 
  #screenheight = 500
  #screenwidth = 500
  #listPoints = 1

Global Quit.b = #False


Declare Biomorph()

;InitEngine3D() ; i move it after button_1 click
;InitSprite()
ExamineDesktops()
OpenWindow(#winOne, 0,0, 200, 200, "control windows..." , #PB_Window_SystemMenu | #PB_Window_MinimizeGadget)
;ButtonGadget(#Gadget, x, y, Width, Height, Text$ [, Flags])
ButtonGadget(#BUTTON_1, 10, 2, 100, 50, "RunMe") 
ButtonGadget(#BUTTON_2, 10, 60, 150, 100, "rotate/stop ") 

InitKeyboard()


Procedure WindowTwo() 
  
OpenWindow(#winTwo, 200, 0, DesktopWidth(0)-300, DesktopHeight(0)-100, "BioMorph fractal", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget)
OpenWindowedScreen(WindowID(#winTwo), 0, 0, DesktopWidth(0)-300, DesktopHeight(0)-100, 0, 0, 0)

SetFrameRate(60)


Add3DArchive(".", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures", #PB_3DArchive_FileSystem)

CreateMaterial(#MAT_plane, LoadTexture(#TEX_plane, "snow_1024.jpg"))
CreatePlane(#plane, 10, 10, 1, 1, 1, 1)
CreateEntity (#plane, MeshID(#plane), MaterialID(#MAT_plane))

CreateLight(0,RGB(255,255,255),-100,40,30)
AmbientColor(RGB(100,100,100))

CreateCamera(#CAMERA, 0, 0, 100, 100)
MoveCamera(#CAMERA, 0, 4, 9)
CameraLookAt(#CAMERA, 0, 2, 0)

RotateCamera(#CAMERA, -15, 0, 0)


SetActiveGadget(#BUTTON_1)
SkyDome("clouds.jpg", 100) ;for blue color background

    CreateMaterial(0, LoadTexture(0, "White.jpg"))
    DisableMaterialLighting(0, #True)
    CreateMesh(1, #PB_Mesh_PointList, #PB_Mesh_Dynamic)
    Biomorph()  ; calling the biomorph generator function
    TransformMesh(1, 0, 2, 0, 1/5, 1/5, 1/5, 0, 0, 0 )
    CreateEntity(1, MeshID(1), MaterialID(0))
    
    rotate = 1
    Repeat
      Event = WindowEvent() 
      If Event = #PB_Event_Gadget
    Select EventGadget()
        Case #BUTTON_2
          If rotate
            rotate ! 1
            Else 
          rotate ! 1
          EndIf
        ;MoveEntity(1, 0,0,-0.5) ; move entity away after every button click
                    
    EndSelect
  EndIf 
    RotateEntity(1, 0,rotate,0, #PB_Relative)
  
   RenderWorld()
   FlipBuffers()
 Until Event = #PB_Event_CloseWindow And EventWindow() = #winTwo
 
 CloseScreen()
 CloseWindow(#winTwo)
 
EndProcedure


Repeat
  Event = WindowEvent()
  If Event = #PB_Event_Gadget
    Select EventGadget()
      Case #BUTTON_1
        InitEngine3D() 
        InitSprite() 
        WindowTwo()
                            
    EndSelect
  EndIf 
    

Until Event = #PB_Event_CloseWindow And EventWindow() = #winOne

Procedure Biomorph()
aspectratio.f = #screenwidth / #screenheight
ymax.f = 10
ymin.f = -ymax
xmax.f = ymax * aspectratio
xmin.f = -xmax 
ilimit.l = #screenheight - 1
jlimit.l = #screenwidth - 1  
x.f: y.f: x0.f: y0.f: xx.f: yy.f
xmax.f = ymax * aspectratio

  For i = 0 To ilimit
   For j = 0 To jlimit
      x0 = xmin + (xmax - xmin) * j / jlimit
      y0 = -ymin - (ymax - ymin) * i / ilimit
      x = x0
      y = y0
      For n = 1 To 100
         xx = x * (x * x - 3 * y * y) + #constreal:   ; THIS Line And the Next give the cube
         yy = y * (3 * x * x - y * y) + #constimag: ; of the Number, plus a constant
         x = xx
         y = yy
         If Abs(x) > 10 Or Abs(y) > 10 Or x * x + y + y > Pow(10,2)
            n = 100
         EndIf
      Next n
      If Abs(x) < 10 Or Abs(y) < 10
        
        ;Plot(j,i, RGB(0,0,0))
        MeshVertexPosition(x0, y0, 0)
        MeshVertexColor(RGB(0,0,0))
        
      Else 
        
        ;Plot(j,i, RGB(255, 255, 255 ))
        MeshVertexPosition(x0, y0, 0)
        MeshVertexColor(RGB(255,255,0)) 
         
      EndIf
            
   Next j
 Next i
 FinishMesh(#True)
  
EndProcedure
Didaktik
User
User
Posts: 79
Joined: Fri Mar 14, 2014 2:12 pm

Re: OGRE in second window?

Post by Didaktik »

Thx!!
User avatar
Bananenfreak
Enthusiast
Enthusiast
Posts: 519
Joined: Mon Apr 15, 2013 12:22 pm

Re: OGRE in second window?

Post by Bananenfreak »

Code: Select all

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;>>                             >>
;>>  Name: dos ventanas         >>
;>>                             >>
;>>  Author: (c) Tom Zähringer  >>
;>>              Chimorin       >>
;>>              Bananenfreak   >>
;>>                             >>
;>>  Date: 07.03.2015           >>
;>>                             >>
;>>  OS: Windows                >>
;>>                             >>
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
EnableExplicit


Define.f KeyX, KeyY, MouseX, MouseY
Define nx.f, nz.f, Boost.f = 1
Define.i Quit, event
#kam_0 = 0
#plane = 0
#planent = 0

Enumeration windows
  #win0
  #win1
EndEnumeration


Enumeration gadgets
  #but0
  #but1
EndEnumeration


Procedure Window0()
  OpenWindow(#win0, 0, 0, 200, 200, "Options", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
  ButtonGadget(#but0, 10, 10, 100, 40, "To Win1")
EndProcedure


Procedure Window1()
  Protected.i boden
  
  
  OpenWindow(#win1, 0, 0, 800, 800, "3D-section", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
  OpenWindowedScreen(WindowID(#win1), 110, 10, 680, 780, 1, 10, 10, #PB_Screen_SmartSynchronization)
  
  WorldShadows(#PB_Shadow_TextureAdditive, 200, RGB(255 * 0.2, 255 * 0.2, 255 * 0.2), 4096)
  
  AmbientColor(RGB(255 * 0.2, 255 * 0.2, 255 * 0.2))
  
  CreatePlane(#plane, 100, 100, 100, 100, 100, 100)
  boden = GetScriptMaterial(#PB_Any, "Scene/GroundBlend")
  CreateEntity(#planent, MeshID(#plane), MaterialID(boden), 0, 0, 0)
  
  ;-Camera
  CreateCamera(#kam_0, 0, 0, 100, 100)
  MoveCamera(#kam_0, 0, 20, 0, #PB_Absolute)
  CameraLookAt(#kam_0, 20, 0, 20)
  CameraRange (#kam_0, 2, 5000)
  CameraFOV   (#kam_0, 90)
  CameraBackColor(#kam_0, RGB(0, 0, 0))
  
  ButtonGadget(#but1, 10, 10, 100, 40, "To Win0")
EndProcedure


If InitEngine3D()
  
  Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures", #PB_3DArchive_FileSystem)
  Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Scripts", #PB_3DArchive_FileSystem)
  Parse3DScripts()
  
  InitSprite()
  InitKeyboard()
  
  Window0()
  
  Repeat
    Repeat
      event = WindowEvent()
      
      Select event
        Case #PB_Event_Gadget
          Select EventGadget()
            Case #but0
              CloseWindow(#win0)
              Window1()
              
            Case #but1
              ;CloseScreen()
              CloseWindow(#win1)
              Window0()
              
          EndSelect
          
        Case #PB_Event_CloseWindow
          Select EventWindow()
            Case #win0
              Quit = 1
              
            Case #win1
              Quit = 1
              
          EndSelect
          
      EndSelect
    Until event = 0
    
    If IsWindow(#win1)
      
      If ExamineKeyboard()
        
        If KeyboardPushed(#PB_Key_Up)    
          MoveCamera(0,  0, 0, -1 * Boost)
        ElseIf KeyboardPushed(#PB_Key_Down)
          MoveCamera(0,  0, 0,  1 * Boost)
        EndIf 
        
        If KeyboardPushed(#PB_Key_Left)  
          MoveCamera(0, -1 * Boost, 0, 0) 
        ElseIf KeyboardPushed(#PB_Key_Right)
          MoveCamera(0,  1 * Boost, 0, 0)
        EndIf
        
        If KeyboardPushed(#PB_Key_Escape)
          quit = 1
        EndIf
        
      EndIf
      
      RenderWorld()
      FlipBuffers()
    EndIf
  Until Quit = 1
  
Else
  MessageRequester("Error", "The 3D Engine can't be initialized", 0)
EndIf

End
Last edited by Bananenfreak on Sat Mar 07, 2015 9:38 am, edited 1 time in total.
Image
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2148
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Re: OGRE in second window?

Post by Andre »

Thanks for the latest example @bananenfreak, but if I change between the two windows (have changed the window sizes/positions in the code to see both windows...) multiple times I get an IMA at the OpenWindowedScreen() command.

Any ideas? Anyone else with this error (I'm here on a MacBook with MacOS 10.5.8 )
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
User avatar
Bananenfreak
Enthusiast
Enthusiast
Posts: 519
Joined: Mon Apr 15, 2013 12:22 pm

Re: OGRE in second window?

Post by Bananenfreak »

I updated the code above and made the second window smaller.
I don´t have MacOS, so I only can guess what it is.
Perhaps the WindowedScreen was too big for your system?
I´ve tested it several times with the old Version an got no IMA.
Image
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: OGRE in second window?

Post by applePi »

Thank you Bananenfreak for the code, i like your idea to use If IsWindow(...) such as:

Code: Select all

If IsWindow(#win1)
      If ExamineKeyboard()
          ...
         If KeyboardPushed(#PB_Key_Escape)
          quit = 1
        EndIf
        
      EndIf
      
      RotateEntity(1,0,rotate,0, #PB_Relative)
      RenderWorld()
      FlipBuffers()
    EndIf
  Until Quit = 1
i have plugged in the fractal procedure with your code which are posted before the update, and it works without errors when going from window 0 to window 1
i kept my previous code for investigation

Code: Select all

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;>>                             >>
;>>  Name: dos ventanas         >>
;>>                             >>
;>>  Author: (c) Tom Z?hringer  >>
;>>              Chimorin       >>
;>>              Bananenfreak   >>
;>>                             >>
;>>  Date: 06.03.2015           >>
;>>                             >>
;>>  OS: Windows                >>
;>>                             >>
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;EnableExplicit

Declare Biomorph()

Define.f KeyX, KeyY, MouseX, MouseY
Define nx.f, nz.f, Boost.f = 1
Define.i Quit, event
#kam_0 = 0
#plane = 0
#planent = 0
#constreal = 0.5 
  #constimag = 0 
  #screenheight = 500
  #screenwidth = 500
  #listPoints = 1

Enumeration windows
  #win0
  #win1
  
EndEnumeration


Enumeration gadgets
  #but0
  #but1
  #but2
EndEnumeration


Procedure Window0()
  OpenWindow(#win0, 0, 0, 200, 200, "Options", #PB_Window_SystemMenu  | #PB_Window_MinimizeGadget)
  ButtonGadget(#but0, 10, 10, 100, 40, "To Win1")
EndProcedure


Procedure Window1()
  Protected.i boden
  
  
  OpenWindow(#win1, 200, 20, 400, 400, "3D-section", #PB_Window_SystemMenu  | #PB_Window_MinimizeGadget)
  OpenWindowedScreen(WindowID(#win1), 110, 10, 400, 400, 0, 10, 10, #PB_Window_SystemMenu  | #PB_Window_MinimizeGadget)
  ButtonGadget(#but1, 10, 10, 100, 40, "To Win0")
  ButtonGadget(#but2, 10, 60, 100, 40, "rot/stop")
  ;WorldShadows(#PB_Shadow_TextureAdditive, 200, RGB(255 * 0.2, 255 * 0.2, 255 * 0.2), 4096)
  
  AmbientColor(RGB(255 * 0.2, 255 * 0.2, 255 * 0.2))
  
  CreatePlane(#plane, 100, 100, 100, 100, 100, 100)
  boden = GetScriptMaterial(#PB_Any, "Scene/GroundBlend")
  CreateEntity(#planent, MeshID(#plane), MaterialID(boden), 0, 0, 0)
  
  ;CreateCube(#cube, 2)
  ;CreateEntity(#cube, MeshID(#cube), #PB_Material_None , -1, 2, -3)
  ;-Camera
  CreateCamera(#kam_0, 0, 0, 100, 100)
  MoveCamera(#kam_0, 0, 3, 10, #PB_Absolute)
  CameraLookAt(#kam_0, 0, 1, 0)
  ;CameraRange (#kam_0, 2, 5000)
  ;CameraFOV   (#kam_0, 90)
  CameraBackColor(#kam_0, RGB(0, 0, 0))
  
  
  SkyDome("clouds.jpg", 100) ;for blue color background

    CreateMaterial(0, LoadTexture(0, "White.jpg"))
    DisableMaterialLighting(0, #True)
    CreateMesh(1, #PB_Mesh_PointList, #PB_Mesh_Dynamic)
    Biomorph()  ; calling the biomorph generator function
    TransformMesh(1, 0, 2, 0, 1/5, 1/5, 1/5, 0, 0, 0 )
    CreateEntity(1, MeshID(1), MaterialID(0), -1, 0, -2)
    
EndProcedure


If InitEngine3D()
  
  Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures", #PB_3DArchive_FileSystem)
  Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Scripts", #PB_3DArchive_FileSystem)
  Parse3DScripts()
  
  InitSprite()
  InitKeyboard()
  
  Window0()
  rotate = 1
  Repeat
    Repeat
      event = WindowEvent()
      
      Select event
        Case #PB_Event_Gadget
          Select EventGadget()
            Case #but0
              
              Window1()
              
            Case #but1
              ;CloseScreen()
              CloseWindow(#win1)
              Window0()
            Case #but2
             If rotate
               rotate ! 1
               Else 
                rotate ! 1
             EndIf  
              
          EndSelect
          
        Case #PB_Event_CloseWindow
          Select EventWindow()
            Case #win0
              Quit = 1
              
            Case #win1
              Quit = 1
              
          EndSelect
          
      EndSelect
    Until event = 0
    
    If IsWindow(#win1)
      
      If ExamineKeyboard()
        
        If KeyboardPushed(#PB_Key_Up)    
          MoveCamera(0,  0, 0, -1 * Boost)
        ElseIf KeyboardPushed(#PB_Key_Down)
          MoveCamera(0,  0, 0,  1 * Boost)
        EndIf 
        
        If KeyboardPushed(#PB_Key_Left)  
          MoveCamera(0, -1 * Boost, 0, 0) 
        ElseIf KeyboardPushed(#PB_Key_Right)
          MoveCamera(0,  1 * Boost, 0, 0)
        EndIf
        
        If KeyboardPushed(#PB_Key_Escape)
          quit = 1
        EndIf
        
      EndIf
      
      RotateEntity(1,0,rotate,0, #PB_Relative)
      RenderWorld()
      FlipBuffers()
    EndIf
  Until Quit = 1
  
Else
  MessageRequester("Error", "The 3D Engine can't be initialized", 0)
EndIf

End

Procedure Biomorph()
aspectratio.f = #screenwidth / #screenheight
ymax.f = 10
ymin.f = -ymax
xmax.f = ymax * aspectratio
xmin.f = -xmax 
ilimit.l = #screenheight - 1
jlimit.l = #screenwidth - 1  
x.f: y.f: x0.f: y0.f: xx.f: yy.f
xmax.f = ymax * aspectratio

  For i = 0 To ilimit
   For j = 0 To jlimit
      x0 = xmin + (xmax - xmin) * j / jlimit
      y0 = -ymin - (ymax - ymin) * i / ilimit
      x = x0
      y = y0
      For n = 1 To 100
         xx = x * (x * x - 3 * y * y) + #constreal:   ; THIS Line And the Next give the cube
         yy = y * (3 * x * x - y * y) + #constimag: ; of the Number, plus a constant
         x = xx
         y = yy
         If Abs(x) > 10 Or Abs(y) > 10 Or x * x + y + y > Pow(10,2)
            n = 100
         EndIf
      Next n
      If Abs(x) < 10 Or Abs(y) < 10
        
        ;Plot(j,i, RGB(0,0,0))
        MeshVertexPosition(x0, y0, 0)
        MeshVertexColor(RGB(0,0,0))
        
      Else 
        
        ;Plot(j,i, RGB(255, 255, 255 ))
        ;MeshVertexPosition(x0, y0, 0)
        ;MeshVertexColor(RGB(255,255,0)) 
         
      EndIf
            
   Next j
 Next i
 FinishMesh(#True)
  
EndProcedure
Post Reply