OpenWindowedScreen, Autostretch and Screen Position

Post bugreports for the Linux version here
#NULL
Addict
Addict
Posts: 1440
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

OpenWindowedScreen, Autostretch and Screen Position

Post by #NULL »

the following code is from the docs of OpenWindowedScreen(), only the empty block of StartDrawing()/StopDrawing() has been added.
If i resize the window by grabbing the bottom window border then the y-position of the screen inside the window gets messed up. making the window larger is shifting the screen upwards and making it smaller shifts it downwards, or at least that's how it looks like.

PureBasic 5.60 (Linux - x64), Ubuntu 16.04.2 LTS.
i did not test it with Windows.

Code: Select all

  If InitSprite() = 0
    MessageRequester("Error", "Can't open screen & sprite environment!", 0)
    End
  EndIf
  
  If OpenWindow(0, 0, 0, 420, 200, "A screen in a window...", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_ScreenCentered)
    CreateStatusBar(0, WindowID(0))
    AddStatusBarField(420)
      
    StatusBarText(0, 0, "Automatically zoomed screen area when changing window size...")
    
    If OpenWindowedScreen(WindowID(0), 0, 0, 420, 200, #True, 0, 20)
  
      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
        
        StartDrawing(ScreenOutput())
        StopDrawing()
      ForEver
      
    Else
      MessageRequester("Error", "Can't open windowed screen!", 0)
    EndIf
  EndIf
#NULL
Addict
Addict
Posts: 1440
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: OpenWindowedScreen, Autostretch and Screen Position

Post by #NULL »

i wasn't sure if something is wrong with my system, so i tested it in a fresh ubuntu studio 17.04 installation (virtual box) and the result is the same.
#NULL
Addict
Addict
Posts: 1440
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: OpenWindowedScreen, Autostretch and Screen Position

Post by #NULL »

can anyone confirm this?

<edit>
whatever you draw directly onto the screen seems to be positioned and scaled correctly:

Code: Select all

        StartDrawing(ScreenOutput())
          Box(0,0,100,100)
          DrawText(0,0,"text")
        StopDrawing()
..but whenever you do it, the Display-commands seem to position incorrectly, and the ClearScreen() too.
walbus
Addict
Addict
Posts: 929
Joined: Sat Mar 02, 2013 9:17 am

Re: OpenWindowedScreen, Autostretch and Screen Position

Post by walbus »

Yep, it's a bug, a buffer problem, openGL specific (All OS)
#NULL
Addict
Addict
Posts: 1440
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: OpenWindowedScreen, Autostretch and Screen Position

Post by #NULL »

Thank you for confirming it. Workaround is to draw to a sprite first and display the sprite to the screen as well as avoiding any other drawing operations directly on the screen.

With the following code I sometimes even get an IMA at 'StartDrawing(ScreenOutput())' in the Else-Branch if resize the window quickly (press D first to switch to ScreenOutput):

Code: Select all

InitSprite()
InitKeyboard()

ww=300
wh=200
sw=ww
sh=wh

win=OpenWindow(#PB_Any, 50,100, ww,wh, "press D to switch screen/sprite drawing", #PB_Window_ScreenCentered | #PB_Window_SystemMenu | #PB_Window_SizeGadget)
OpenWindowedScreen(WindowID(win), 0,0, sw,sh, 1,0,0)

screenSpr = CreateSprite(#PB_Any,sw,sh,#PB_Sprite_AlphaBlending)
switch = 1

w = 32
h = 32
sprGreen = CreateSprite(#PB_Any, w, h, #PB_Sprite_AlphaBlending)
StartDrawing(SpriteOutput(sprGreen))
	DrawingMode(#PB_2DDrawing_AllChannels)
	Box(0, 0, w, h, $ff00ff00)
StopDrawing()

clearColor = $336699

Repeat
	ExamineKeyboard()
	
	Repeat
		event = WindowEvent()
		Select event
			Case #PB_Event_CloseWindow
				quit = #True
		EndSelect
	Until Not event
	
	If KeyboardReleased(#PB_Key_D)
	  switch ! 1
	EndIf
	
	If switch
	  StartDrawing(SpriteOutput(screenSpr))
	    DrawingMode(#PB_2DDrawing_AllChannels)
	    Box(0,0,OutputWidth(),OutputHeight(),clearColor)
	    DrawingMode(#PB_2DDrawing_AlphaBlend | #PB_2DDrawing_Transparent)
	    For k=0 To OutputHeight()-1 Step 2
	      For i=0 To OutputWidth()-1 Step 2
	        Box(i, k, 1, 1, $ffff0000)
	      Next
	    Next
  		DrawText(0,0,"SpriteOutput")
  	StopDrawing()
  	DisplayTransparentSprite(screenSpr, 0, 0)
	Else
  	StartDrawing(ScreenOutput())
; 	    DrawingMode(#PB_2DDrawing_AllChannels)
; 	    Box(0,0,OutputWidth(),OutputHeight(),clearColor)
	    DrawingMode(#PB_2DDrawing_AlphaBlend | #PB_2DDrawing_Transparent)
	    For k=0 To OutputHeight()-1 Step 2
	      For i=0 To OutputWidth()-1 Step 2
	        Box(i, k, 1, 1, $ffff0000)
	      Next
	    Next
  		DrawText(0,0,"ScreenOutput")
  	  
	    DrawingMode(#PB_2DDrawing_AlphaBlend | #PB_2DDrawing_Transparent)
  		DrawText(0,0,"ScreenOutput")
  	  
  	StopDrawing()
	EndIf
	
	DisplayTransparentSprite(sprGreen, 10, 10)
		
	FlipBuffers()
	ClearScreen(clearColor)
Until quit Or KeyboardPushed(#PB_Key_Escape)
Post Reply