Page 1 of 1

Windowed screen and Ogre

Posted: Fri Jun 04, 2004 9:17 am
by Momiji
Hi all! :D
May be this is a silly question for you experts in Pure Basic (i am more than a beginner in PB), but it's very important to me, so please help if you can!

This is the question: I need to open a window and put in some buttons (Gadgets in PB) and in the same window, i need to open a screen bind to ogre 3D engine (fully supported by PB).

If acting on the buttons/gadget in the parent window, it should be able to update the world rendered on the windowed screen...

Is it possible to open and handle such a kind of 3d screen within a "window +gadgets" in PB?

Thank you all :D

Posted: Fri Jun 04, 2004 11:05 am
by fweil
Momiji,

Here is a skeletton to place more code ...

Hope this helps.

Rgrds

Code: Select all

Enumeration
  #Window_Main
EndEnumeration

#Background = $602020

;
; Main starts here
;

  Quit = #FALSE
  WindowXSize = 800
  WindowYSize = 600
  ScreenXSize = 640
  ScreenYSize = 480
  If OpenWindow(#Window_Main, 0, 0, WindowXSize, WindowYSize, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered, "MyWindow")
      If InitEngine3D() And InitSprite()
          OpenWindowedScreen(WindowID(), WindowXSize - ScreenXSize, WindowYSize - ScreenYSize, ScreenXSize, ScreenYSize, #TRUE, 5, 25)
      EndIf
      AddKeyboardShortcut(0, #PB_Shortcut_Escape, #PB_Shortcut_Escape)
      LoadFont(0, "Verdana", 12)
      FontID = FontID()
      If CreateGadgetList(WindowID())
          SetGadgetFont(#PB_Default, FontID)
          ;
          ; Here put your gadgets (also you can add a toolbar below or above
          ;
      EndIf
      
      If CreateStatusBar(0, WindowID())
      EndIf

      Repeat
        Select WindowEvent()
          Case #PB_EventCloseWindow
            Quit = #TRUE
          Case #PB_EventMenu
            Select EventMenuID()
              Case #PB_Shortcut_Escape
                Quit = #TRUE
            EndSelect
          Case #PB_EventGadget
            Select EventGadgetID()
            EndSelect
        EndSelect
        Delay(1)
        FlipBuffers()
        ClearScreen(0, 0, 0)
      Until Quit
  EndIf
End

Posted: Fri Jun 04, 2004 11:37 am
by Momiji
:D Thank you very much! I will handle some "cut and paste" code from example and see if it can fit my needs...

Posted: Fri Jun 04, 2004 12:07 pm
by Momiji
So here you are what I meant, here there is an example of "cut & paste" from example PB code and yours and it works!!!
Thank you again a lot :D
Momiji

Code: Select all

Enumeration 
  #Window_Main 
EndEnumeration 

#Background = $602020 

;********************* Start added code *******************************************

#FALSE = 0
#true = 1
#CameraSpeed = 10

;********************* End added code *******************************************

; 
; Main starts here 
; 

  Quit = #FALSE 
  WindowXSize = 800 
  WindowYSize = 600 
  ScreenXSize = 640 
  ScreenYSize = 480 
  If OpenWindow(#Window_Main, 0, 0, WindowXSize, WindowYSize, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered, "MyWindow") 
      If InitEngine3D() And InitSprite() 
          OpenWindowedScreen(WindowID(), WindowXSize - ScreenXSize, WindowYSize - ScreenYSize, ScreenXSize, ScreenYSize, #TRUE, 5, 25) 
          

;********************* Start added code *******************************************          
          InitKeyboard()

          Add3DArchive("Data\", #PB_3DArchive_FileSystem)
          AmbientColor(RGB(0,200,0))  ; Green 'HUD' like color 
 
          CreateMaterial(0, LoadTexture(0, "r2skin.jpg"))
          CreateEntity(0, LoadMesh(0, "Robot.mesh"), MaterialID(0))
          AnimateEntity(0, "Walk")
    
          CreateCamera(0, 0, 0, 100, 50)  ; Front camera
          CameraLocate(0,0,0,100)
    
          CreateCamera(1, 0, 50, 100, 50) ; Back camera
          CameraLocate(1,0,0,-100)
          RotateCamera(1,180,0,0)
    
          CameraRenderMode(1, #PB_Camera_Plot)  
          
          
          
;********************* End added code *******************************************          
          
          
          
      EndIf 
      AddKeyboardShortcut(0, #PB_Shortcut_Escape, #PB_Shortcut_Escape) 
      LoadFont(0, "Verdana", 12) 
      FontID = FontID() 
      If CreateGadgetList(WindowID()) 
          SetGadgetFont(#PB_Default, FontID) 
          ; 
          ; Here put your gadgets (also you can add a toolbar below or above 
          ; 

;********************* Start added code **********************************

          Top = 10
          GadgetHeight = 24
          
          Frame3DGadget(#PB_Any, 10, Top, 370, 90, "Player...") : Top+20

          StringGadget(0,  20, Top, 200, GadgetHeight, "")
          ButtonGadget(1, 223, Top,  72, GadgetHeight, "Play")
          ButtonGadget(2, 295, Top,  72, GadgetHeight, "Stop")  : Top+35
          DisableGadget(2,1)
          ButtonGadget(8, 100, 86, 80, 24, "Quit")


;********************* End added code *******************************************          
          
      EndIf 
      
      If CreateStatusBar(0, WindowID()) 
      EndIf 

      Repeat 
        Select WindowEvent() 
          Case #PB_EventCloseWindow 
            Quit = #TRUE 
          Case #PB_EventMenu 
            Select EventMenuID() 
              Case #PB_Shortcut_Escape 
                Quit = #TRUE 
            EndSelect 
          Case #PB_EventGadget 
            Select EventGadgetID() 

;********************* Start added code **********************************
            
            Case 1 ; Play
               DisableGadget(2,0)  ; Enable the 'Stop' gadget
               DisableGadget(1,1)  ; Disable the 'Play' Gadget
      
            Case 2 ; Stop
               DisableGadget(1,0)  ; Enable the 'Play' gadget
               DisableGadget(2,1)  ; Disable the 'Stop' Gadget

            Case 8 ; Quit...
               Quit = #TRUE
;********************* End added code *******************************************          
            
            EndSelect 
        EndSelect 
        
;******************* Start added code *********************************************

      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

          
     RotateEntity(0, 1, 0, 0)
      
     RotateCamera(0, MouseX, MouseY, RollZ)
     MoveCamera  (0, KeyX, 0, KeyY)
      
     RotateCamera(1, MouseX, MouseY, RollZ)
     MoveCamera  (1, KeyX, 0, KeyY)
      
     RenderWorld()

     FlipBuffers()


;****************** End added code **********************************************


;****************** Start Commented out code ***********************
;        Delay(1) 
;        FlipBuffers() 
;        ClearScreen(0, 0, 0) 
;****************** End Commented out code ***********************


      Until Quit 
  EndIf 
End

Posted: Fri Jun 04, 2004 1:02 pm
by fweil
momiji,

here are just a few updates :

- for a better usage of resources just let a short delay(1-5 ms should be enough) at the end of the main event loop.
- I changed some things in the keyboard management. Just have a look and play with arrows and numeric pad keys
- I added a different cursor display when the cursor is inside the screen and outside. This will probably help you in going further to allow the user ie to drag the robot or anything you will imagine.

The mouse position is managed using WindowMouseX() and WindowMouseY() because if you use InitMouse() and ExamineMouse() this will lock the mouse to the screen management and will not allow to manage the window part outside of the screen part.

So just some more ideas for a larger overview.

Anyway you converted my short code well and I am confident you will design nice work ...

Code: Select all

Enumeration 
  #Window_Main 
EndEnumeration 

#Background = $602020 

;********************* Start added code ******************************************* 

#FALSE = 0 
#true = 1 
CameraSpeed = 0

;********************* End added code ******************************************* 

; 
; Main starts here 
; 

  Quit = #FALSE 
  WindowXSize = 800 
  WindowYSize = 600 
  ScreenXSize = 640 
  ScreenYSize = 480 
  If OpenWindow(#Window_Main, 0, 0, WindowXSize, WindowYSize, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered, "MyWindow") 
      If InitEngine3D() And InitSprite() And InitKeyboard() And InitMouse()
          OpenWindowedScreen(WindowID(), WindowXSize - ScreenXSize, WindowYSize - ScreenYSize, ScreenXSize, ScreenYSize, #TRUE, 5, 25) 
          

;********************* Start added code *******************************************          

          Add3DArchive("C:\Recup\PureBasic\Examples\Sources\Data\", #PB_3DArchive_FileSystem) 
          AmbientColor(RGB(0,200,0))  ; Green 'HUD' like color 

          CreateMaterial(0, LoadTexture(0, "r2skin.jpg")) 
          CreateEntity(0, LoadMesh(0, "Robot.mesh"), MaterialID(0)) 
          AnimateEntity(0, "Walk") 
    
          CreateCamera(0, 0, 0, 100, 50)  ; Front camera 
          CameraLocate(0,0,0,100) 
    
          CreateCamera(1, 0, 50, 100, 50) ; Back camera 
          CameraLocate(1,0,0,-100) 
          RotateCamera(1,180,0,0) 
    
          CameraRenderMode(1, #PB_Camera_Plot)  
          
          
          
;********************* End added code *******************************************          
          
          
          
      EndIf 
      AddKeyboardShortcut(0, #PB_Shortcut_Escape, #PB_Shortcut_Escape) 
      LoadFont(0, "Verdana", 12) 
      FontID = FontID() 
      If CreateGadgetList(WindowID()) 
          SetGadgetFont(#PB_Default, FontID) 
          ; 
          ; Here put your gadgets (also you can add a toolbar below or above 
          ; 

;********************* Start added code ********************************** 

          Top = 10 
          GadgetHeight = 24 
          
          Frame3DGadget(#PB_Any, 10, Top, 370, 90, "Player...") : Top+20 

          StringGadget(0,  20, Top, 200, GadgetHeight, "") 
          ButtonGadget(1, 223, Top,  72, GadgetHeight, "Play") 
          ButtonGadget(2, 295, Top,  72, GadgetHeight, "Stop")  : Top+35 
          DisableGadget(2,1) 
          ButtonGadget(8, 100, 86, 80, 24, "Quit") 


;********************* End added code *******************************************          
          
      EndIf 
      
      hCursorArrow = LoadCursor_(0, #IDC_ARROW)
      hCursorCross = LoadCursor_(0, #IDC_CROSS)

      If CreateStatusBar(0, WindowID()) 
      EndIf 

      SetCursorPos_(WindowMouseX, WindowMouseY)
      Repeat 
        Select WindowEvent() 
          Case #PB_EventCloseWindow 
            Quit = #TRUE 
          Case #PB_EventMenu 
            Select EventMenuID() 
              Case #PB_Shortcut_Escape 
                Quit = #TRUE 
            EndSelect 
          Case #PB_EventGadget 
            Select EventGadgetID() 

;********************* Start added code ********************************** 
            
            Case 1 ; Play 
               DisableGadget(2,0)  ; Enable the 'Stop' gadget 
               DisableGadget(1,1)  ; Disable the 'Play' Gadget 
      
            Case 2 ; Stop 
               DisableGadget(1,0)  ; Enable the 'Play' gadget 
               DisableGadget(2,1)  ; Disable the 'Stop' Gadget 

            Case 8 ; Quit... 
               Quit = #TRUE 
;********************* End added code *******************************************          
            
            EndSelect 
        EndSelect 
        
;******************* Start added code ********************************************* 

        ExamineKeyboard() 
        If KeyboardPushed(#PB_Key_Left) : KeyX = -CameraSpeed : CameraSpeed + 1 : MoveCamera(0, KeyX / 10, 0, 0) : ElseIf KeyboardReleased(#PB_Key_Left) : CameraSpeed = 0 : EndIf
        If KeyboardPushed(#PB_Key_Right) : KeyX = CameraSpeed : CameraSpeed + 1 : MoveCamera(0, KeyX / 10, 0, 0) : ElseIf KeyboardReleased(#PB_Key_Right) : CameraSpeed = 0 : EndIf
        If KeyboardPushed(#PB_Key_Up) : KeyY = -CameraSpeed : CameraSpeed + 1 : MoveCamera(0, 0, 0, KeyY / 10) : ElseIf KeyboardReleased(#PB_Key_Up) : CameraSpeed = 0 : EndIf
        If KeyboardPushed(#PB_Key_Down) : KeyY = CameraSpeed : CameraSpeed + 1 : MoveCamera(0, 0, 0, KeyY / 10) : ElseIf KeyboardReleased(#PB_Key_Down) : CameraSpeed = 0 : EndIf
        If KeyboardPushed(#PB_Key_Pad6) : xCam = CameraSpeed : CameraSpeed + 1 : RotateCamera(0, xCam / 10, 0, 0) : ElseIf KeyboardReleased(#PB_Key_Pad6) : CameraSpeed = 0 : EndIf
        If KeyboardPushed(#PB_Key_Pad4) : xCam = -CameraSpeed : CameraSpeed + 1 : RotateCamera(0, xCam / 10, 0, 0) : ElseIf KeyboardReleased(#PB_Key_Pad4) : CameraSpeed = 0 : EndIf
        If KeyboardPushed(#PB_Key_Pad2) : yCam = -CameraSpeed : CameraSpeed + 1 : RotateCamera(0, 0, yCam / 10, 0) : ElseIf KeyboardReleased(#PB_Key_Pad2) : CameraSpeed = 0 : EndIf
        If KeyboardPushed(#PB_Key_Pad8) : yCam = CameraSpeed : CameraSpeed + 1 : RotateCamera(0, 0, yCam / 10, 0) : ElseIf KeyboardReleased(#PB_Key_Pad8) : CameraSpeed = 0 : EndIf
        If KeyboardPushed(#PB_Key_Pad3) : zCam = -CameraSpeed : CameraSpeed + 1 : RotateCamera(0, 0, 0, zCam / 10) : ElseIf KeyboardReleased(#PB_Key_Pad3) : CameraSpeed = 0 : EndIf
        If KeyboardPushed(#PB_Key_Pad9) : zCam = CameraSpeed : CameraSpeed + 1 : RotateCamera(0, 0, 0, zCam / 10) : ElseIf KeyboardReleased(#PB_Key_Pad9) : CameraSpeed = 0 : EndIf
        
        WindowMouseX = WindowMouseX() - 5
        WindowMouseY = WindowMouseY() - 23
        If WindowMouseX => (WindowXSize - ScreenXSize) And WindowMouseX <= (WindowXSize - 5) And WindowMouseY => (WindowYSize - ScreenYSize) And WindowMouseY <= (WindowYSize - 25)
            SetCursor_(hCursorCross)
          Else
            SetCursor_(hCursorArrow)
        EndIf
        RotateEntity(0, 1, 0, 0) 

        RenderWorld() 

        FlipBuffers() 


;****************** End added code ********************************************** 


;****************** Start Commented out code *********************** 
        Delay(5) ; let this delay to not consume the whole CPU
;        FlipBuffers() 
;        ClearScreen(0, 0, 0) 
;****************** End Commented out code *********************** 


      Until Quit 
  EndIf 
End

Posted: Fri Jun 04, 2004 1:37 pm
by Comtois
i cant explain in english , but i am sure you will understand
try this

Code: Select all

    pourcentx.f=ScreenXSize*100/WindowXSize
    pourcenty.f=ScreenYSize*100/WindowYSize
    CreateCamera(0, 0, 0, pourcentx, pourcenty/2)  ; Front camera 
    CameraBackColor(0,RGB(0,0,255))
    CameraLocate(0,0,0,100) 
    
    CreateCamera(1, 0, pourcenty/2, pourcentx, pourcenty/2) ; Back camera 
    CameraLocate(1,0,0,-100) 
    RotateCamera(1,180,0,0) 
    CameraBackColor(1,RGB(255,0,0))
    CameraRenderMode(1, #PB_Camera_Wireframe) 
or this on ( conserve proportions )

Code: Select all

    pourcentx.f=ScreenXSize*100/WindowXSize
    pourcenty.f=ScreenYSize*100/WindowYSize
    CreateCamera(0, 0, 0, pourcentx/2, pourcenty/2)  ; Front camera 
    CameraBackColor(0,RGB(0,0,255))
    CameraLocate(0,0,0,100) 
    
    CreateCamera(1, 0, pourcenty/2, pourcentx/2, pourcenty/2) ; Back camera 
    CameraLocate(1,0,0,-100) 
    RotateCamera(1,180,0,0) 
    CameraBackColor(1,RGB(255,0,0))
    CameraRenderMode(1, #PB_Camera_Wireframe) 

Posted: Sat Jun 05, 2004 7:45 am
by Momiji
Thank you fweil and comtois for your code and hints, very precious for me.
I am a real beginner in PB (started yesterday to look at it) and I am not aware of all the possibility it gives to programmers...

Thank you very much for your help and hints :D

Momiji

Posted: Wed Aug 02, 2006 1:51 am
by klaver
Why the app crashes when the window is resized or minimized?