# &#39;Flip&#39; - &quot;don&#39;t clear&quot; parameter

**URL:** <https://psychtoolbox.discourse.group/t/39-flip-39-quot-don-39-t-clear-quot-parameter/2089>\
**Category:** Uncategorized\
**Created:** [November 24, 2005, 11:21am UTC](https://psychtoolbox.discourse.group/t/39-flip-39-quot-don-39-t-clear-quot-parameter/2089 "2005-11-24T11:21:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Allen\_Ingling](https://avatars.discourse-cdn.com/v4/letter/a/a183cd/32.png) [@Allen\_Ingling](https://psychtoolbox.discourse.group/u/Allen_Ingling)\
**Post date:** [November 24, 2005, 11:21am UTC](https://psychtoolbox.discourse.group/t/39-flip-39-quot-don-39-t-clear-quot-parameter/2089/1 "2005-11-24T11:21:24Z")

</div>

Dear Forum,  
  
I am using the latest release of the Psychtoolbox for Mac OS X.   
  
For the purpose of my experiment, it is important to have a white rectangle in the lower   
left corner during the presentation of the actual stimuli.  
The actual stimuli are 'flipped' a lot, and while the rectangle mustn't be affected by those   
'Flip' commands, I 'flip' the rectangle as follows:  
  
Screen('Flip', w, [], 1); % where the last 'don't clear' parameter is set to '1'.  
  
to prevent it from being cleared.   
  
But: of course the next normal 'Flip' clears it and this is exactly what it should do to all the   
other graphical elements, but not to the rectangle.  
Is there any way to spare the rectangle permanently from getting 'flipped' away?   
  
So basically I am looking for a way to make the white rectangle part of the background   
(just as the initial   
  
black=BlackIndex(0);  
Screen('FillRect',w, black);   
Screen('Flip', w);  
  
causes the blackground to be black)  
though it should be possible to switch off / hide the white rectangle from time to time.  
  
I would be glad to hear any suggestion!  
  
Thanks,  
  
-Fabian Stelzer

---

<div class="post-metadata">

**Author:** ![mariokleiner](https://avatars.discourse-cdn.com/v4/letter/m/13edae/32.png) [@mariokleiner](https://psychtoolbox.discourse.group/u/mariokleiner)\
**Post date:** [November 25, 2005, 12:49am UTC](https://psychtoolbox.discourse.group/t/39-flip-39-quot-don-39-t-clear-quot-parameter/2089/2 "2005-11-25T00:49:41Z")

</div>

Dear Fabian,  
  
what you want (only clearing parts of the screen) is not possible and  
won't be in the future unless somebody can provide a very convincing  
reason for the need of such a function.  
  
But the obvious solution is to simply redraw your white rectangle after  
invocation of Screen('Flip')... -- What's wrong with that simple solution?  
  
Just for the record: There are three clearmodes...  
  
dontclear=2 -- The content of the backbuffer after Screen('Flip') is  
identical to the previous content of the frontbuffer -- the image that  
was on display \*before\* the Flip command is now available for overdrawing.  
This mode is the fastest - it takes 0.0 Milliseconds.  
  
dontclear=0 -- This is the default mode: The backbuffer is cleared to  
background color. Takes a bit of time, depending on display resolution  
and performance of your gfx-card maybe between 0.1 ms and 2 ms.  
  
dontclear=1 -- Keep content after Flip - This is the slowest method,  
because its implemented via making a backup copy of the buffer before  
Flip and then restore buffer from backup after flip. Can take from 1 ms  
up to multiple milliseconds. This mode is mostly meant for stimuli that  
are so complex to draw that redrawing them from scratch would cost  
much more time than the multiple milliseconds that dontclear=1 itself  
needs.  
  
dontclear=2 can be interesting if one overdraws a specific area of the  
screen after each Flip anyway, e.g., if you present a centered image  
that changes at each redraw. Then you could do:  
  
Screen('FillRect', win, 0); % Clear buffer with black.  
Screen('Flip', win); % Show blank screen.  
Screen('Flip', win); % Show blank screen, clear 2nd buffer.  
  
for i=1:trials  
 % Overdraw stuff from last trial with new stuff from...  
 % new trial. Needs special caution when using Alpha-  
 % blending...  
 ...  
 % Flip buffers. Don't clear or restore anything...  
 Screen('Flip', win, [], 2);  
end;  
  
best,  
-mario  
  

> --- In [psychtoolbox@yahoogroups.com](mailto:psychtoolbox@yahoogroups.com), "fabian\_stelzer" \<fabian\_stelzer@y...\> wrote:  
> \>  
> \> Dear Forum,  
> \>   
> \> I am using the latest release of the Psychtoolbox for Mac OS X.   
> \>   
> \> For the purpose of my experiment, it is important to have a white rectangle in the lower   
> \> left corner during the presentation of the actual stimuli.  
> \> The actual stimuli are 'flipped' a lot, and while the rectangle mustn't be affected by   
> those   
> \> 'Flip' commands, I 'flip' the rectangle as follows:  
> \>   
> \> Screen('Flip', w, [], 1); % where the last 'don't clear' parameter is set to '1'.  
> \>   
> \> to prevent it from being cleared.   
> \>   
> \> But: of course the next normal 'Flip' clears it and this is exactly what it should do to all   
> the   
> \> other graphical elements, but not to the rectangle.  
> \> Is there any way to spare the rectangle permanently from getting 'flipped' away?   
> \>   
> \> So basically I am looking for a way to make the white rectangle part of the background   
> \> (just as the initial   
> \>   
> \> black=BlackIndex(0);  
> \> Screen('FillRect',w, black);   
> \> Screen('Flip', w);  
> \>   
> \> causes the blackground to be black)  
> \> though it should be possible to switch off / hide the white rectangle from time to time.  
> \>   
> \> I would be glad to hear any suggestion!  
> \>   
> \> Thanks,  
> \>   
> \> -Fabian Stelzer  
> \>

---

<div class="post-metadata">

**Author:** ![Allen\_Ingling](https://avatars.discourse-cdn.com/v4/letter/a/a183cd/32.png) [@Allen\_Ingling](https://psychtoolbox.discourse.group/u/Allen_Ingling)\
**Post date:** [November 25, 2005, 1:07pm UTC](https://psychtoolbox.discourse.group/t/39-flip-39-quot-don-39-t-clear-quot-parameter/2089/3 "2005-11-25T13:07:46Z")

</div>

Dear Mario,  
  
thanks for your reply.   
I need the 'white rectangle' to indicate an eye-tracker when to start tracking and when to   
stop - via a photodiode attached on the lower left corner of the screen ;-)  
I'll try if it works with redrawing the rectangle everytime...  
I agree, other than that, this rectangle thing is a very strange wish to have.  
Thanks anyways,  
  
-Fabian  
  

> --- In [psychtoolbox@yahoogroups.com](mailto:psychtoolbox@yahoogroups.com), "Mario Kleiner" \<mario.kleiner@t...\> wrote:  
> \>  
> \> Dear Fabian,  
> \>   
> \> what you want (only clearing parts of the screen) is not possible and  
> \> won't be in the future unless somebody can provide a very convincing  
> \> reason for the need of such a function.  
> \>   
> \> But the obvious solution is to simply redraw your white rectangle after  
> \> invocation of Screen('Flip')... -- What's wrong with that simple solution?  
> \>   
> \> Just for the record: There are three clearmodes...  
> \>   
> \> dontclear=2 -- The content of the backbuffer after Screen('Flip') is  
> \> identical to the previous content of the frontbuffer -- the image that  
> \> was on display \*before\* the Flip command is now available for overdrawing.  
> \> This mode is the fastest - it takes 0.0 Milliseconds.  
> \>   
> \> dontclear=0 -- This is the default mode: The backbuffer is cleared to  
> \> background color. Takes a bit of time, depending on display resolution  
> \> and performance of your gfx-card maybe between 0.1 ms and 2 ms.  
> \>   
> \> dontclear=1 -- Keep content after Flip - This is the slowest method,  
> \> because its implemented via making a backup copy of the buffer before  
> \> Flip and then restore buffer from backup after flip. Can take from 1 ms  
> \> up to multiple milliseconds. This mode is mostly meant for stimuli that  
> \> are so complex to draw that redrawing them from scratch would cost  
> \> much more time than the multiple milliseconds that dontclear=1 itself  
> \> needs.  
> \>   
> \> dontclear=2 can be interesting if one overdraws a specific area of the  
> \> screen after each Flip anyway, e.g., if you present a centered image  
> \> that changes at each redraw. Then you could do:  
> \>   
> \> Screen('FillRect', win, 0); % Clear buffer with black.  
> \> Screen('Flip', win); % Show blank screen.  
> \> Screen('Flip', win); % Show blank screen, clear 2nd buffer.  
> \>   
> \> for i=1:trials  
> \> % Overdraw stuff from last trial with new stuff from...  
> \> % new trial. Needs special caution when using Alpha-  
> \> % blending...  
> \> ...  
> \> % Flip buffers. Don't clear or restore anything...  
> \> Screen('Flip', win, [], 2);  
> \> end;  
> \>   
> \> best,  
> \> -mario  
> \>   
> \> --- In [psychtoolbox@yahoogroups.com](mailto:psychtoolbox@yahoogroups.com), "fabian\_stelzer" \<fabian\_stelzer@y...\> wrote:  
> \> \>  
> \> \> Dear Forum,  
> \> \>   
> \> \> I am using the latest release of the Psychtoolbox for Mac OS X.   
> \> \>   
> \> \> For the purpose of my experiment, it is important to have a white rectangle in the   
> lower   
> \> \> left corner during the presentation of the actual stimuli.  
> \> \> The actual stimuli are 'flipped' a lot, and while the rectangle mustn't be affected by   
> \> those   
> \> \> 'Flip' commands, I 'flip' the rectangle as follows:  
> \> \>   
> \> \> Screen('Flip', w, [], 1); % where the last 'don't clear' parameter is set to '1'.  
> \> \>   
> \> \> to prevent it from being cleared.   
> \> \>   
> \> \> But: of course the next normal 'Flip' clears it and this is exactly what it should do to   
> all   
> \> the   
> \> \> other graphical elements, but not to the rectangle.  
> \> \> Is there any way to spare the rectangle permanently from getting 'flipped' away?   
> \> \>   
> \> \> So basically I am looking for a way to make the white rectangle part of the   
> background   
> \> \> (just as the initial   
> \> \>   
> \> \> black=BlackIndex(0);  
> \> \> Screen('FillRect',w, black);   
> \> \> Screen('Flip', w);  
> \> \>   
> \> \> causes the blackground to be black)  
> \> \> though it should be possible to switch off / hide the white rectangle from time to   
> time.  
> \> \>   
> \> \> I would be glad to hear any suggestion!  
> \> \>   
> \> \> Thanks,  
> \> \>   
> \> \> -Fabian Stelzer  
> \> \>  
> \>
