Windowed screen and Ogre

Just starting out? Need help? Post your questions and find answers here.
Momiji
New User
New User
Posts: 4
Joined: Fri Jun 04, 2004 9:08 am

Windowed screen and Ogre

Post 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
fweil
Enthusiast
Enthusiast
Posts: 725
Joined: Thu Apr 22, 2004 5:56 pm
Location: France
Contact:

Post 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
My avatar is a small copy of the 4x1.8m image I created and exposed at 'Le salon international du meuble à Paris' january 2004 in Matt Sindall's 'Shades' designers exhibition. The original laminated print was designed using a 150 dpi printout.
Momiji
New User
New User
Posts: 4
Joined: Fri Jun 04, 2004 9:08 am

Post 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...
Momiji
New User
New User
Posts: 4
Joined: Fri Jun 04, 2004 9:08 am

Post 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
fweil
Enthusiast
Enthusiast
Posts: 725
Joined: Thu Apr 22, 2004 5:56 pm
Location: France
Contact:

Post 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
My avatar is a small copy of the 4x1.8m image I created and exposed at 'Le salon international du meuble à Paris' january 2004 in Matt Sindall's 'Shades' designers exhibition. The original laminated print was designed using a 150 dpi printout.
User avatar
Comtois
Addict
Addict
Posts: 1431
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Post 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) 
Please correct my english
http://purebasic.developpez.com/
Momiji
New User
New User
Posts: 4
Joined: Fri Jun 04, 2004 9:08 am

Post 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
klaver
Enthusiast
Enthusiast
Posts: 147
Joined: Wed Jun 28, 2006 6:55 pm
Location: Schröttersburg

Post by klaver »

Why the app crashes when the window is resized or minimized?
Post Reply