OpenWindowedScreen()

Advanced game related topics
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

OpenWindowedScreen()

Post by IdeasVacuum »

The code below is Example2 from the help pages, where the Windowed Screen should auto-stretch with the parent Window. It works fine as-is, but fails in two ways if InitEngine3D() is enabled at the top of the code:

1) It does not auto-stretch;
2) The windowed screen flickers (does not do so if auto-stretch is disabled or #PB_Screen_NoSynchronization is set).

Am I right to assume this is a limitation rather than a bug?

Code: Select all

InitEngine3D()
 
If InitSprite() = 0
 
    MessageRequester("Error", "Can't open screen & sprite environment!", 0)
    End
    
EndIf
  
If OpenWindow(0, 0, 0, 320, 200, "A screen in a window...", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_ScreenCentered)
  
      CreateStatusBar(0, WindowID(0))
      AddStatusBarField(320)
      
      StatusBarText(0, 0, "Automatically zoomed screen area when changing window size...")
    
          If OpenWindowedScreen(WindowID(0), 0, 0, 320, 200, 1, 0, 20)  ; we don't need  exact screen width/height,
                                                                                                 ; because it will be automatically stretched...
  
               CreateSprite(0, 50, 50) ; Create an empty sprite, will be whole black
        
               Repeat
                   ; It's very important to process all the events remaining in the queue at each frame
                   ;
                     Repeat
                     
                         Event = WaitWindowEvent(10)
          
                             If Event = #PB_Event_CloseWindow
                             
                                 End
                                 
                             EndIf
                             
                     Until Event = 0
        
                   FlipBuffers()
                   ClearScreen(RGB(0, 0, 200)) ; A blue background
                   DisplaySprite(0, 10, 10)  ; Display our black box at the left-top corner
                   DisplaySprite(0, 260, 10) ; Display our black box at the right-top corner
               
               ForEver
      
          Else
          
                MessageRequester("Error", "Can't open windowed screen!", 0)
                
          EndIf
EndIf
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Re: OpenWindowedScreen()

Post by Kaeru Gaman »

seems to be a problem with the Engine3D.
comment the InitEngine3D out and it works.
oh... and have a nice day.
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: OpenWindowedScreen()

Post by IdeasVacuum »

Hi Kaeru
Kaeru Gaman wrote:seems to be a problem with the Engine3D.
comment the InitEngine3D out and it works.
Yeah, that is what I have said but using other words :)

....but I don't know if it's a PB bug or InitEngine3D simply is not supported in this case.

However, your response to my query about Screen/Window focus probably has given me enough clues to code up a solution.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: OpenWindowedScreen()

Post by IdeasVacuum »

Having Established that a Windowed Screen cannot be auto-resized if Engine3D is being used, coding to detect a change in size of the Parent Window and re-size the Windowed Screen is required. In fact the Windowed Screen is not re-sized, it's destroyed and replaced. The use of CloseScreen() is very much a work-around because everything currently displayed in the Windowed Screen is lost - Entities (Meshs) and sprites.

However, When I try to apply this method, drawing the replacement Windowed Screen fails at OpenWindowedScreen.

Test Code:

Code: Select all

; #### Constants ####
#False             = 0
#True              = 1
#WINDOW        = 2
#Camera1         = 3
#StatusBar       = 4

; #### Declare Procedures ####
Declare WnddScreen()
Declare WaitForUser()
Declare ShowForm()

; #### Vars ####
Global     igWnddScrnResize.i = #False
Global    igWnddScrnCreated.i = #False
Global  igEngineInitialised.i = #False

Global  igWindowWidthX.i = 400
Global igWindowHeightY.i = 300
Global    igScreenWthX.i = 300
Global    igScreenHgtY.i = 200


Procedure WnddScreen()
;---------------------
; # Define a Windowed Screen

Shared igEngineInitialised
Shared igScreenWthX
Shared igScreenHgtY

If (igWnddScrnResize = #True)

     CloseScreen()

EndIf

If (igEngineInitialised = #True)

       If OpenWindowedScreen(WindowID(#WINDOW), 50, 60, igScreenWthX, igScreenHgtY, 0, 0, 0, #PB_Screen_NoSynchronization)

             igWnddScrnCreated = #True

                  CreateCamera(#Camera1, 0, 0, 100, 100) ; Front camera 100% of screen area
               CameraBackColor(#Camera1, 7615787)

       Else

               igWnddScrnCreated = #False
               MessageRequester("Problem","Could not create/resize Windowed Screen",#PB_MessageRequester_Ok | #MB_ICONERROR)

       EndIf

Else

       MessageRequester("Problem","Could not Initialise 3D Engine",#PB_MessageRequester_Ok | #MB_ICONERROR)

EndIf

EndProcedure


Procedure TestWindow()
;----------------------

; # Define a Window containing a Windowed Screen

Shared igEngineInitialised

; #### Start 3D Engine ####

    igEngineInitialised = InitEngine3D()

If (igEngineInitialised = #True)

        If ( (InitSprite() = #False) Or (InitKeyboard() = #False) Or (InitMouse() = #False))

                MessageRequester("Problem","Could not Initialise DirectX",#PB_MessageRequester_Ok | #MB_ICONERROR)
                End
        EndIf

      ; #### Draw Window ####

      If OpenWindow(#WINDOW, 0, 0, igWindowWidthX, igWindowHeightY, "OpenWindowedScreen Resize Test   [ESC] to Exit", #PB_Window_SizeGadget | #PB_Window_ScreenCentered)

                       ExamineDesktops()

                       WindowBounds(#WINDOW, igWindowWidthX, igWindowHeightY, DesktopWidth(0), DesktopHeight(0))

                    CreateStatusBar(#StatusBar, WindowID(#WINDOW))
                     SetWindowColor(#WINDOW, 14794425)

               ; #### Draw WindowedScreen ####

               WnddScreen()

      EndIf

Else
      MessageRequester("Problem","Could not Initialise 3D Engine",#PB_MessageRequester_Ok | #MB_ICONERROR)
      End

EndIf

EndProcedure


Procedure WaitForUser()
;-----------------------

Shared igWindowHeightY
Shared  igWindowWidthX
Shared    igScreenWthX
Shared    igScreenHgtY

Define       iWinWidthX.i
Define      iWinHeightY.i

Define           iEvent.i

Repeat ; Start of the event loop

            ExamineKeyboard()

            iEvent = WaitWindowEvent() ; Wait until an event is received from Windows

        If (iEvent = #PB_Event_SizeWindow)

                ; ### Did the User re-size the Window?

                 iWinWidthX = WindowWidth(#WINDOW)
                iWinHeightY = WindowHeight(#WINDOW)

                If ( (iWinWidthX <> igWindowWidthX) Or (iWinHeightY <> igWindowHeightY) )

                      ; Redraw WindowedScreen to Resize

                           igWindowWidthX = iWinWidthX
                          igWindowHeightY = iWinHeightY

                             igScreenWthX = igWindowWidthX - 100
                             igScreenHgtY = igWindowHeightY - 100

                         igWnddScrnResize = #True
                        igMeshIsDisplayed = #False

                        WnddScreen()

                EndIf

        EndIf

Until KeyboardPushed(#PB_Key_Escape)

EndProcedure

; #### Main ####

TestWindow()
WaitForUser()

Being unable to offer a re-sizable Window is not a catastrophe but if anyone has devised a way to achieve it it would be nice to know. I think a PB enhancement to OpenWindowedScreen so that it auto-re sizes with Engine3D in use would be a good thing. :)
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Post Reply