Flickers White Screen opening a Windowed Screen

Just starting out? Need help? Post your questions and find answers here.
SoulReaper
Enthusiast
Enthusiast
Posts: 372
Joined: Sun Apr 03, 2005 2:14 am
Location: England

Flickers White Screen opening a Windowed Screen

Post by SoulReaper »

Hello :)

I seem to be have a problem with the following code below i have checked it on PB 4.31 on Windows XP & PB 4.41 and Windows 7 and they are the same.

The program seems to flicker white for a few flips in windowed mode then goes black as expected, its the few flickers i cannot seem to understand why this is happening...
in full screen mode it is fine, any help please :?

it is more pronouced in debug mode.

Code: Select all



   Version$="v1.2"

   _Window=#True


  If InitEngine3D()=0
    MessageRequester("Error", "Failed to open 3D Engine", 0) : End
  EndIf

   If InitKeyboard()=0 Or InitSprite()=0
   MessageRequester("Error", "Can't open DirectX 7 or Greater", 0) : End
   EndIf

   ExamineDesktops()
   MonitorFrequency=DesktopFrequency(0)
   If MonitorFrequency=0 : MessageRequester("Error", "Failed to open a 800*600 screen!",0) : End : EndIf

   If _Window=#False
     If OpenScreen(800,600,16,version$,#PB_Screen_WaitSynchronization,MonitorFrequency)
       Else
        MessageRequester("Error", "Failed to open a 800*600 16 bit screen",0)
     EndIf
   EndIf


   If _Window=#True
    OpenWindow(0,0,0,800,600,Version$,#PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_SizeGadget|#PB_Window_MaximizeGadget)
     If OpenWindowedScreen(WindowID(0),0,0,800,600,1,0,0,#PB_Screen_WaitSynchronization)
       Else
        MessageRequester("Error", "Failed to open a 800*600 32 bit screen",0)
     EndIf
   EndIf


  Repeat
    ExamineKeyboard()

    FlipBuffers()

    If _Window=#True
      Repeat
          Event=WindowEvent()
          If Event=#PB_Event_CloseWindow : End : EndIf
      Until Event=0
    EndIf

    Until KeyboardPushed(#PB_Key_Escape) 

Thankyou for any help
Kevin :)
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Re: Flickers White Screen opening a Windowed Screen

Post by Kaeru Gaman »

ok.. now you got me wondering.

I tested it and it PERMANENTLY flickers.
even if I add the missing ClearScreen,
put InitEngine3D after InitSprite,
add a RenderWorld() to the Mainloop...
nothing helps.

only when I eliminate InitEngine3D the flicker vanishes...

don't get this... why is Engine3D not fully compatible with a WindowedScreen?

btw, I got XPpro
oh... and have a nice day.
User avatar
Demivec
Addict
Addict
Posts: 4267
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Flickers White Screen opening a Windowed Screen

Post by Demivec »

Kaeru Gaman wrote:ok.. now you got me wondering.

I tested it and it PERMANENTLY flickers.
even if I add the missing ClearScreen,
put InitEngine3D after InitSprite,
add a RenderWorld() to the Mainloop...
nothing helps.

only when I eliminate InitEngine3D the flicker vanishes...

don't get this... why is Engine3D not fully compatible with a WindowedScreen?
I get identical results with Windows XP SP3 x86.

In addition, I ran software a week ago and have rebooted several times (keeping the computer powered up) since then and I get portions of these former images as part of the flicker. :shock:
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Re: Flickers White Screen opening a Windowed Screen

Post by nco2k »

the startup flicker has nothing to do with the engine3d and it isnt white either, its the window background color. i reported something similar (see 2nd part). no flickering in 4.20.

c ya,
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: Flickers White Screen opening a Windowed Screen

Post by Trond »

About the permanent flicker:
When you use the 3d engine, the 2d drawing is done on top of the 3d image. But, you never render any 3d image in your code, so all you get is garbage. Note that to use RenderWorld() you need to create a camera first, else you'll still get garbage.

Code: Select all

Version$="v1.2"

_Window=#True

InitSprite()
InitEngine3D()



If _Window=#False
  OpenScreen(800,600,16,version$,#PB_Screen_WaitSynchronization,MonitorFrequency)
Else
  OpenWindow(0,0,0,800,600,Version$,#PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_SizeGadget|#PB_Window_MaximizeGadget)
  OpenWindowedScreen(WindowID(0),0,0,800,600,1,0,0,#PB_Screen_WaitSynchronization)
EndIf

CreateCamera(0, 0, 0, 800, 600)
Debug "done"

Repeat
  
  RenderWorld()
  FlipBuffers()

  If _Window=#True
    Repeat
        Event=WindowEvent()
        If Event=#PB_Event_CloseWindow : End : EndIf
    Until Event=0
  EndIf

Until 0=1
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Re: Flickers White Screen opening a Windowed Screen

Post by Kaeru Gaman »

Trond wrote: Note that to use RenderWorld() you need to create a camera first ...
goodness you ... goodness me Image industrial desease ...

my mistake, thanks for enlighting.
oh... and have a nice day.
SoulReaper
Enthusiast
Enthusiast
Posts: 372
Joined: Sun Apr 03, 2005 2:14 am
Location: England

Re: Flickers White Screen opening a Windowed Screen

Post by SoulReaper »

Thankyou for trying to help but it still fickers when flipping buffers at the very beginning in windowed mode :?
this time i have took out all 3d commands just to show that it is still there... :?

Code: Select all

Version$="v1.2"
_Window=#True

InitSprite()

If _Window=#False
  OpenScreen(800,600,16,version$,#PB_Screen_WaitSynchronization,MonitorFrequency)
Else
  OpenWindow(0,0,0,800,600,Version$,#PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_SizeGadget|#PB_Window_MaximizeGadget)
  OpenWindowedScreen(WindowID(0),0,0,800,600,1,0,0,#PB_Screen_WaitSynchronization)
EndIf

Repeat
  
  FlipBuffers()

  If _Window=#True
    Repeat
        Event=WindowEvent()
        If Event=#PB_Event_CloseWindow : End : EndIf
    Until Event=0
  EndIf

Until 0=1

Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: Flickers White Screen opening a Windowed Screen

Post by Trond »

Confirmed.
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Re: Flickers White Screen opening a Windowed Screen

Post by Kaeru Gaman »

I also conform this short flicker, but when I compile an exe it shortens down to a single frame's blink.

I don't know what's the reason, but compared with the three seconds of sheer blackness the resolution change causes when opening a fullscreen, it appears meaningless to me.
oh... and have a nice day.
SoulReaper
Enthusiast
Enthusiast
Posts: 372
Joined: Sun Apr 03, 2005 2:14 am
Location: England

Re: Flickers White Screen opening a Windowed Screen

Post by SoulReaper »

@Trond and Kaeru Gaman and nco2k thankyou for confirming this problem, the reason why it bothers me is that it looks unprofessional.

Maybe Fred and Team could look into this in more depth as windowed screens are used alot in Pure Basic.

I will post this on the bugs section.

Kind Regards
Kevin :)
moogle
Enthusiast
Enthusiast
Posts: 372
Joined: Tue Feb 14, 2006 9:27 pm
Location: London, UK

Re: Flickers White Screen opening a Windowed Screen

Post by moogle »

This problem has been with PB for quite a while IIRC (v4.00?)

I've whittled it down to the WindowEvent() procedure
This code shows the screen how I thought it would be, but if you uncomment the Event = WindowEvent() line the screen shows Blue (RGB(0, 64, 127)) and then white, then back to Blue. I don't know how to make it work properly and handle the window events? It's one of these things where you think ahh PB is awesome and then find annoying little bugs like this. Like it's been said in other posts the white flicker is more prominent in debug mode.

What's weird is when I try to record it with screen capture the window opens fine, with the Event handling in.

Looks like the only way to stop this happening is to use API (SDL or some others) to open your own windowed screen...

Would be nice if the PB team could comment here or in the bug post, because it sort of seems to me that the Sprite/Screen/Game parts of PB are much lesser priority :(

PS - It works fine if compiled under the OpenGL subsystem.

Code: Select all

If (InitSprite() And InitSprite3D()) = 0
  MessageRequester("Error", "Can't open DirectX", 0)
  End
EndIf

pWnd=OpenWindow(#PB_Any, 0, 0, 640, 480, "PB White Flicker", #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered | #PB_Window_BorderLess)
If pWnd
	SetWindowColor(pWnd, RGB(0,64,127))
  If Not OpenWindowedScreen(WindowID(pWnd), 0, 0, 640, 480, 0, 0, 0, #PB_Screen_SmartSynchronization)
  	MessageRequester("Error", "Can't open windowed screen!", 0)
    End
  EndIf
Else
	MessageRequester("Error", "Can't open window!", 0)
EndIf


Repeat
	Repeat
		;Event = WindowEvent()
		Select Event
			Case #PB_Event_CloseWindow
				Quit = 1
		EndSelect
	Until Event = 0
	
	ClearScreen(RGB(0,64,127))
	FlipBuffers()
	Delay(10)
Until  Quit Or (GetKeyState_(#VK_ESCAPE)&%10000000 And GetActiveWindow() = pWnd)
CloseScreen()
End
Image
User avatar
Rescator
Addict
Addict
Posts: 1769
Joined: Sat Feb 19, 2005 5:05 pm
Location: Norway

Re: Flickers White Screen opening a Windowed Screen

Post by Rescator »

I see no flicker here (too fast probably) but I did notice this oddity...

Does the same happen to others?
Wat happens for me is that the first flipbuffer loop (3 frames of flipping) seem to do nothing.
It is only if If the main loop flip buffer is used that the window actually turns black.

Code: Select all

Version$="v1.2"

   _Window=#True


  If InitEngine3D()=0
    MessageRequester("Error", "Failed to open 3D Engine", 0) : End
  EndIf

   If InitKeyboard()=0 Or InitSprite()=0
   MessageRequester("Error", "Can't open DirectX 7 or Greater", 0) : End
   EndIf

   ExamineDesktops()
   MonitorFrequency=DesktopFrequency(0)
   If MonitorFrequency=0 : MessageRequester("Error", "Failed to open a 800*600 screen!",0) : End : EndIf

   If _Window=#False
     If OpenScreen(800,600,16,version$,#PB_Screen_WaitSynchronization,MonitorFrequency)
       Else
        MessageRequester("Error", "Failed to open a 800*600 16 bit screen",0)
     EndIf
   EndIf


   If _Window=#True
    OpenWindow(0,0,0,800,600,Version$,#PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_SizeGadget|#PB_Window_MaximizeGadget|#PB_Window_Invisible)
     
        If OpenWindowedScreen(WindowID(0),0,0,800,600,1,0,0,#PB_Screen_WaitSynchronization)
            Define i.i
			  Repeat
			    If _Window=#True
			      Repeat
			          Event=WindowEvent()
			      Until Event=0
			    EndIf
			
			 	  FlipBuffers()
			    ExamineKeyboard()
			 	  i+1
       		Until i=3
     			HideWindow(0,#False)
        Else
           MessageRequester("Error", "Failed to open a 800*600 32 bit screen",0)
        EndIf
   EndIf

  Repeat


    If _Window=#True
      Repeat
          Event=WindowEvent()
          If Event=#PB_Event_CloseWindow : End : EndIf
      Until Event=0
    EndIf

;    FlipBuffers()
    ExamineKeyboard()
    Until KeyboardPushed(#PB_Key_Escape)
    
moogle
Enthusiast
Enthusiast
Posts: 372
Joined: Tue Feb 14, 2006 9:27 pm
Location: London, UK

Re: Flickers White Screen opening a Windowed Screen

Post by moogle »

Rescator wrote:I see no flicker here (too fast probably) but I did notice this oddity...

Does the same happen to others?
Wat happens for me is that the first flipbuffer loop (3 frames of flipping) seem to do nothing.
It is only if If the main loop flip buffer is used that the window actually turns black.

By a flicker I mean if the ClearScreen color is black and the window color is black when I open a window like the code above it will open a window with a black background, then when it creates the windowedscreen (PB's DirectX version) it flashes white and then after it's cleared one more time it goes back to black and then it's all alright.

OpenGL has no white flashes.

Yes your code doesn't turn the screen black for me too.
I think the main loop turns it black because whilst the window is hidden flipbuffers doesn't work.

If you check the WindowEvent() values in the first loop (window hidden) they just return 0 and 1 which arent event types it seems?

This was fixed in another version and then it appeared again. I'm guessing it's when the 2DDrawing changed but I'm going to check.
Image
moogle
Enthusiast
Enthusiast
Posts: 372
Joined: Tue Feb 14, 2006 9:27 pm
Location: London, UK

Re: Flickers White Screen opening a Windowed Screen

Post by moogle »

moogle wrote:What's weird is when I try to record it with screen capture the window opens fine, with the Event handling in.
Bit of a correction, it just seems that the flicker is random and not a screen capture program stopping it.
After recording another thing I thought I'd record this one too just to see if it ever shows up.

http://www.youtube.com/watch?v=EHMUmQTf_Mg&hd=1

It never existed before PB4.4 iirc.
Image
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Flickers White Screen opening a Windowed Screen

Post by netmaestro »

Check the bugs forum, it's fixed for the upcoming 4.60b4.
BERESHEIT
Post Reply