# DrawTexture color behaving oddly

**URL:** <https://psychtoolbox.discourse.group/t/drawtexture-color-behaving-oddly/1673>\
**Category:** Uncategorized\
**Created:** [March 2, 2012, 5:15pm UTC](https://psychtoolbox.discourse.group/t/drawtexture-color-behaving-oddly/1673 "2012-03-02T17:15:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jardine\_nl](https://avatars.discourse-cdn.com/v4/letter/j/ba8739/32.png) [@jardine\_nl](https://psychtoolbox.discourse.group/u/jardine_nl)\
**Post date:** [March 2, 2012, 5:15pm UTC](https://psychtoolbox.discourse.group/t/drawtexture-color-behaving-oddly/1673/1 "2012-03-02T17:15:10Z")

</div>

I'm having a strange issue: I'm not receiving any errors in the command window, but my textures aren't being fully filled in with the specified color. &nbsp;Everything else works.

  

Here are the relevant lines of code:&nbsp;

  

Screen('BlendFunction', MainWindow, 'GL\_SRC\_ALPHA', 'GL\_ONE\_MINUS\_SRC\_ALPHA');

rectWSP = 8.5; rectHSP = 50.5;  
  
template &nbsp; = Screen('MakeTexture', MainWindow, [0 0 rectWSP rectHSP]);  
sourceRect = [0 0 rectWSP rectHSP];  
stimRect &nbsp; = [-rectWSP/2, -rectHSP/2, rectWSP/2, rectHSP/2];&nbsp;

rects(r,:) = CenterRectOnPoint(stimRect, centroid(1)-400+100\*r, centroid(2)+200);

Screen('DrawTextures', MainWindow, template, sourceRect, rects(r,:), orientations(r), [], [], stimCol(1,:);

stimCol is set to, say, [0 250 100], but the textures then appear to be half green and half black ([like this](http://imgur.com/rGajw)&nbsp;).

I'm using OSX 10.7.2 with Java 1.6.0\_29, and MATLAB 7.10.0 with PTB 3.0.9. Any help would be greatly appreciated!

- Nicole

---

<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:** [March 4, 2012, 5:47am UTC](https://psychtoolbox.discourse.group/t/drawtexture-color-behaving-oddly/1673/2 "2012-03-04T05:47:50Z")

</div>

--- In [psychtoolbox@yahoogroups.com](mailto:psychtoolbox@yahoogroups.com), "jardine\_nl" \<jardinenotsardine@...\> wrote:  

> \>  
> \> Fixed -- instead of using MakeTexture to create the texture index, for some reason creating the texture index using OpenOffscreenWindow works.   
> \> \>

It is not clear why that should work either, because this ...  
  
template = Screen('MakeTexture', MainWindow, [0 0 rectWSP rectHSP]);  
  
... is wrong: You are converting an image into a texture which consists of four gray value pixels with the values 0, 0 , rectWSP and rectHSP. Your texture is a 4 pixel image with the gray values 0, 0, 8 and 50, so no surprise that half of your texture is black.  
  
What you probably wanted was:  
  
template = Screen('MakeTexture', MainWindow, 255 \* ones(rectHSP, rectWSP));  
  
or  
  
template = Screen('OpenOffscreenwindow', MainWindow, 255, [0 0 rectWSP rectHSP]);  
  
but rectWSP = 8.5; rectHSP = 50.5; is a no-go with fractional values in such a case.  
  
I assume you use textures here instead of simple 'FillRect', because you want to rotate them by arbitrary angles? Otherwise 'FillRect' would be more simple.  
  
-mario  
  
  

> \> - Nicole  
> \>   
> \> --- In [psychtoolbox@yahoogroups.com](mailto:psychtoolbox@yahoogroups.com), "jardine\_nl" \<jardinenotsardine@\> wrote:  
> \> \>  
> \> \> I'm having a strange issue: I'm not receiving any errors in the command  
> \> \> window, but my textures aren't being fully filled in with the specified  
> \> \> color. Everything else works.  
> \> \> Here are the relevant lines of code:  
> \> \>   
> \> \> Screen('BlendFunction', MainWindow, 'GL\_SRC\_ALPHA',  
> \> \> 'GL\_ONE\_MINUS\_SRC\_ALPHA');  
> \> \>   
> \> \> rectWSP = 8.5; rectHSP = 50.5;  
> \> \>   
> \> \> template = Screen('MakeTexture', MainWindow, [0 0 rectWSP rectHSP]);  
> \> \> sourceRect = [0 0 rectWSP rectHSP];  
> \> \> stimRect = [-rectWSP/2, -rectHSP/2, rectWSP/2, rectHSP/2];  
> \> \>   
> \> \>   
> \> \> rects(r,:) = CenterRectOnPoint(stimRect, centroid(1)-400+100\*r,  
> \> \> centroid(2)+200);  
> \> \>   
> \> \>   
> \> \>   
> \> \> Screen('DrawTextures', MainWindow, template, sourceRect, rects(r,:),  
> \> \> orientations(r), [], [], stimCol(1,:);  
> \> \>   
> \> \>   
> \> \>   
> \> \>   
> \> \> stimCol is set to, say, [0 250 100], but the textures then appear to be  
> \> \> half green and half black (like this \<[http://imgur.com/rGajw](http://imgur.com/rGajw)\> ).  
> \> \>   
> \> \> I'm using OSX 10.7.2 with Java 1.6.0\_29, and MATLAB 7.10.0 with PTB  
> \> \> 3.0.9. Any help would be greatly appreciated!  
> \> \>   
> \> \>   
> \> \>   
> \> \>   
> \> \> - Nicole  
> \> \>  
> \>
