# Screen(‘BlendFunction’) applying different versions to different textures on the same screen

**URL:** <https://psychtoolbox.discourse.group/t/screen-blendfunction-applying-different-versions-to-different-textures-on-the-same-screen/3465>\
**Category:** Programming Help\
**Created:** [October 25, 2020, 11:07am UTC](https://psychtoolbox.discourse.group/t/screen-blendfunction-applying-different-versions-to-different-textures-on-the-same-screen/3465 "2020-10-25T11:07:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dilcetan](https://yyz2.discourse-cdn.com/free1/user_avatar/psychtoolbox.discourse.group/dilcetan/32/334_2.png) [@dilcetan](https://psychtoolbox.discourse.group/u/dilcetan)\
**Post date:** [October 25, 2020, 11:07am UTC](https://psychtoolbox.discourse.group/t/screen-blendfunction-applying-different-versions-to-different-textures-on-the-same-screen/3465/1 "2020-10-25T11:07:16Z")

</div>

Hi, It seems like I need to use  
Screen(‘BlendFunction’, win, ‘GL\_SRC\_ALPHA’, ‘GL\_ONE\_MINUS\_SRC\_ALPHA’) to create my grating properly in my code. I also want to use CreateProceduralGasussBlob function superimposed to my grating. However it seems like CreateProceduralGasussBlob requires me to use  
Screen(‘BlendFunction’, win, GL\_ONE, GL\_ONE). Otherwise it doesn’t look like a Gaussian blob. Is there a way that I can use different parameters of Screen(‘BlendFunction’) for different textures at the same time on the same screen?  
Thank you for the help!

---

<div class="post-metadata">

**Author:** ![dcnieho](https://avatars.discourse-cdn.com/v4/letter/d/779978/32.png) [@dcnieho](https://psychtoolbox.discourse.group/u/dcnieho)\
**Post date:** [October 25, 2020, 11:34am UTC](https://psychtoolbox.discourse.group/t/screen-blendfunction-applying-different-versions-to-different-textures-on-the-same-screen/3465/2 "2020-10-25T11:34:35Z")

</div>

It should work fine (I think) to call Screen(‘BlendFunction’,…) right before each place where you need to change it, give that a try.

Cheers,  
Dee

---

<div class="post-metadata">

**Author:** ![czuba](https://yyz2.discourse-cdn.com/free1/user_avatar/psychtoolbox.discourse.group/czuba/32/68_2.png) [@czuba](https://psychtoolbox.discourse.group/u/czuba)\
**Post date:** [November 10, 2020, 4:29pm UTC](https://psychtoolbox.discourse.group/t/screen-blendfunction-applying-different-versions-to-different-textures-on-the-same-screen/3465/3 "2020-11-10T16:29:06Z")

</div>

Yep, we do it all the time for displays that incorporate anti-aliased dots & procedural gabors.

There is some overhead in applying the Screen(‘BlendFunction’…) switch, so you’d just want to be sure to group all of your procedural drawing together, switch to GL\_ONE, draw all your blobs, switch back to ‘alpha-one-minus-alpha’ — as opposed to toggling back & forth in a loop “1 grating, 1 dot, 1 grating, 1 dot, …”

e.g.

```matlab
% must change blend function for procedural gabor rendering
% ...only one BlendFunction to set, not separate for each stereobuffer.
[prevSrcRect, prevDestRect] = Screen('BlendFunction', p.trial.display.ptr, 'GL_ONE', 'GL_ONE');
drawTheGabors(p, sn);
% reset previous blend functions
Screen('BlendFunction', p.trial.display.ptr, prevSrcRect, prevDestRect);

```

-Thad.

---

<div class="post-metadata">

**Author:** ![dilcetan](https://yyz2.discourse-cdn.com/free1/user_avatar/psychtoolbox.discourse.group/dilcetan/32/334_2.png) [@dilcetan](https://psychtoolbox.discourse.group/u/dilcetan)\
**Post date:** [November 11, 2020, 12:50pm UTC](https://psychtoolbox.discourse.group/t/screen-blendfunction-applying-different-versions-to-different-textures-on-the-same-screen/3465/4 "2020-11-11T12:50:41Z")

</div>

Thank you for your response. Thad. This is really helpful!
