It is currently Sun Sep 23, 2018 3:51 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: startdrawing(screenoutput()) not drawing on the backbuffer
PostPosted: Wed Aug 15, 2018 1:14 pm 
Offline
User
User
User avatar

Joined: Mon Feb 26, 2018 10:41 pm
Posts: 47
Location: Netherlands
I have some code here and when i tryied to work with it completely by the programming rules. The screen stay blank. This is the whole code

Code:
If InitSprite() = 0 Or InitKeyboard() = 0 Or InitSound() = 0 Or InitSprite() = 0
  MessageRequester("Error", "Unable to init system utilities (Possible Direct X7 or higher not installed!)", 0)
  End
EndIf

OpenWindow(0, 0, 0, 640, 480, "A screen in a window...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
If OpenWindowedScreen(WindowID(0), 0, 0, 640, 480) = 0
  MessageRequester("Error", "Can't open windowed screen!", 0)
  End
EndIf


StartDrawing(ScreenOutput())
Box(5,5,100,100,RGB(255,255,255))
StopDrawing()
FlipBuffers()
ClearScreen(0)

Repeat
 
  ;Exit the program by keyboard or X on window
  ExamineKeyboard()
  If KeyboardPushed(#PB_Key_Escape)
    End
  EndIf
  Event = WindowEvent()
  If event = #PB_Event_CloseWindow
    End
  EndIf
 
ForEver


If I remove 2 lines the program is working. But for me this means that the drawing is done on the front buffer()

Code:
If InitSprite() = 0 Or InitKeyboard() = 0 Or InitSound() = 0 Or InitSprite() = 0
  MessageRequester("Error", "Unable to init system utilities (Possible Direct X7 or higher not installed!)", 0)
  End
EndIf

OpenWindow(0, 0, 0, 640, 480, "A screen in a window...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
If OpenWindowedScreen(WindowID(0), 0, 0, 640, 480) = 0
  MessageRequester("Error", "Can't open windowed screen!", 0)
  End
EndIf


StartDrawing(ScreenOutput())
Box(5,5,100,100,RGB(255,255,255))
StopDrawing()
;Commneting these out so the compiler is not compile them
;FlipBuffers()
;ClearScreen(0)
;My box is showing Strange....
Repeat
 
  ;Exit the program by keyboard or X on window
  ExamineKeyboard()
  If KeyboardPushed(#PB_Key_Escape)
    End
  EndIf
  Event = WindowEvent()
  If event = #PB_Event_CloseWindow
    End
  EndIf
 
ForEver

Is there an error or is there something wrong.

Do i code the lines startdrawing .. Trough clearscreen(0) inside the repeat...Forever loop the code is working to.
But then i think its start drawing on the backbuffer. But why does this happend with only the first drawing command.

_________________
From my first self made computer till now I stil like computers.


Top
 Profile  
Reply with quote  
 Post subject: Re: startdrawing(screenoutput()) not drawing on the backbuff
PostPosted: Wed Aug 15, 2018 3:28 pm 
Offline
Enthusiast
Enthusiast

Joined: Thu Aug 30, 2007 11:54 pm
Posts: 788
Location: right here
FlipBuffers() kinda depends on the event processing IIRC and your screen/window content might get discarded by a window repaint. If you don't want to always redraw you can use a simple flag. Also it's much better if you process all available events in a second/nested loop before doing anything else in the main loop.
Code:
If InitSprite() = 0 Or InitKeyboard() = 0 Or InitSound() = 0 Or InitSprite() = 0
  MessageRequester("Error", "Unable to init system utilities (Possible Direct X7 or higher not installed!)", 0)
  End
EndIf

OpenWindow(0, 0, 0, 640, 480, "A screen in a window...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
If OpenWindowedScreen(WindowID(0), 0, 0, 640, 480) = 0
  MessageRequester("Error", "Can't open windowed screen!", 0)
  End
EndIf

Procedure update()
  ClearScreen(0)
  StartDrawing(ScreenOutput())
  Box(5,5,100,100,RGB(255,255,255))
  StopDrawing()
  FlipBuffers()
EndProcedure

doUpdate = #True

;PostEvent(#PB_Event_Repaint)

Repeat
  ExamineKeyboard()
  If KeyboardPushed(#PB_Key_Escape)
    End
  EndIf
  While WindowEvent()
    If Event() = #PB_Event_CloseWindow
      End
    ElseIf Event() = #PB_Event_Repaint
      doUpdate = #True
    EndIf
  Wend
  If doUpdate
    update()
    doUpdate = #False
  EndIf
ForEver


<edit>
the code was misleading. when reseting doUpdate = #False it doesn't work. sorry.


Top
 Profile  
Reply with quote  
 Post subject: Re: startdrawing(screenoutput()) not drawing on the backbuff
PostPosted: Thu Aug 16, 2018 9:48 pm 
Offline
User
User
User avatar

Joined: Mon Feb 26, 2018 10:41 pm
Posts: 47
Location: Netherlands
Thanks for the relply.

Your code is working. And i think i know how its work now. That was a little bit confusing. When the procedure is using the flipbuffer is working ok. When direct command the flipbuffer is not working correct. As you said its al in windows that discarding the refresh of the screen. But the repaint event is standing. I checked it and it wil alway be a event when the program is starting up. That is a beautifull way of refreshing the screen first before doing anyting on it.

Thanks for the info this give me a little bit more understanding of PB. There is to much to learn of it.

_________________
From my first self made computer till now I stil like computers.


Top
 Profile  
Reply with quote  
 Post subject: Re: startdrawing(screenoutput()) not drawing on the backbuff
PostPosted: Thu Aug 16, 2018 11:45 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Thu Mar 24, 2011 12:40 am
Posts: 523
Location: Iowa, USA
I noticed that you used InitSprite() two times in your first line of code.
It may not make a difference but I thought I would mention it just in case.

_________________
BasicallyPure
Until you know everything you know nothing, all you have is what you believe.


Top
 Profile  
Reply with quote  
 Post subject: Re: startdrawing(screenoutput()) not drawing on the backbuff
PostPosted: Sun Aug 19, 2018 6:58 pm 
Offline
User
User
User avatar

Joined: Mon Feb 26, 2018 10:41 pm
Posts: 47
Location: Netherlands
Sorry for the double initSprite()

its a typo. In theoriginal program its gone.

bart

_________________
From my first self made computer till now I stil like computers.


Top
 Profile  
Reply with quote  
 Post subject: Re: startdrawing(screenoutput()) not drawing on the backbuff
PostPosted: Sun Aug 19, 2018 9:13 pm 
Offline
PureBasic Expert
PureBasic Expert
User avatar

Joined: Fri Apr 25, 2003 4:34 pm
Posts: 845
Location: Canada
Your screen looks blank because you clear it after flipping it into view...
Code:
StartDrawing(ScreenOutput())
Box(5,5,100,100,RGB(255,255,255))
StopDrawing()
FlipBuffers()
ClearScreen(0) ;<-----


You should clear your screen, do your drawing operations and then flip into view...
Code:
ClearScreen(0)
StartDrawing(ScreenOutput())
Box(5,5,100,100,RGB(255,255,255))
StopDrawing()
FlipBuffers()

_________________
Image Image


Top
 Profile  
Reply with quote  
 Post subject: Re: startdrawing(screenoutput()) not drawing on the backbuff
PostPosted: Sun Aug 19, 2018 9:32 pm 
Offline
User
User
User avatar

Joined: Mon Feb 26, 2018 10:41 pm
Posts: 47
Location: Netherlands
Its beautifull replyed. But your missing the code:

The drawing supposed te be on the backbuffer of the screen.
When drawing is finished the flip command is switching the front and back screen.
The backscreen (Not visable) is now the drawing screen.
I need to clear the screen before i can draw again.

What you say is that i am drawing on the front screen and then switch screens. That not good. I take more time to
draw on a screen that is in view than drawing on the background screen.

What my code problem was: That it was drawing the first frame on the frondscreen.
The problem is that windows is not working so wel in this case.

When i do this in full screen mode the filpping andclearen is working fine.

But thaks anyway for you view over it.

bart.

_________________
From my first self made computer till now I stil like computers.


Top
 Profile  
Reply with quote  
 Post subject: Re: startdrawing(screenoutput()) not drawing on the backbuff
PostPosted: Sun Aug 19, 2018 9:37 pm 
Offline
Enthusiast
Enthusiast

Joined: Thu Aug 30, 2007 11:54 pm
Posts: 788
Location: right here
ClearScreen() and drawing operate on the backbuffer. after the flip the new backbuffer is cleared while the previous/drawn buffer is now front.

Code:
clear > draw > flip > clear > draw > flip

is the same as
Code:
        draw > flip > clear > draw > flip > clear

(except for the initial clear)
At least it doesn't seem to make a difference on linux and is also what I remember from windows. I guess it has rather to do with the event processing.


Top
 Profile  
Reply with quote  
 Post subject: Re: startdrawing(screenoutput()) not drawing on the backbuff
PostPosted: Tue Aug 21, 2018 7:40 pm 
Offline
User
User
User avatar

Joined: Mon Feb 26, 2018 10:41 pm
Posts: 47
Location: Netherlands
Yep you are right.

But for the best result the first option is prefered. But in the most time I do it on the second way which can give some times
a odd responce of the screen. Like a dark blink of the screen if the screen has a different color then black.

Thank for the info.

bart.

_________________
From my first self made computer till now I stil like computers.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 20 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye