# OSX:  bug report: using drawtext cripples drawtexture?

**URL:** <https://psychtoolbox.discourse.group/t/osx-bug-report-using-drawtext-cripples-drawtexture/1011>\
**Category:** Uncategorized\
**Created:** [January 14, 2005, 10:26am UTC](https://psychtoolbox.discourse.group/t/osx-bug-report-using-drawtext-cripples-drawtexture/1011 "2005-01-14T10:26:15Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![franswcornelissen](https://avatars.discourse-cdn.com/v4/letter/f/df705f/32.png) [@franswcornelissen](https://psychtoolbox.discourse.group/u/franswcornelissen)\
**Post date:** [January 14, 2005, 10:26am UTC](https://psychtoolbox.discourse.group/t/osx-bug-report-using-drawtext-cripples-drawtexture/1011/1 "2005-01-14T10:26:15Z")

</div>

I've found that using drawtext prior to using drawtexture cripples the   
latter function. Instead of the image I am expecting I get a white   
square the size of the image.  
The code below demonstrates the effect.  
  
First, run the script with 'usedrawtext' set to 0. For me, all works   
fine (image appears twice, first using drawtexture, second time using   
putimage).  
Then, set it to 1. Now I first get a white square, then the image   
(drawn using putimage).  
It doesn't matter whether the drawtext is issued before or after   
maketexture, so it appears something is affecting drawtexture.  
  
Gr.  
  
Frans  
  
%-------------------------------------------  
  
% playing with textures  
try  
  
 usedrawtext=0; % draw some text on screen before grabbing the image.  
 usedrawtextafter=0; % draw some text on screen after having grabbed   
the image.  
 usegetimage=1; % get image from screen, 0=generate some random noise  
  
  
 commandwindow;  
 screenNumber=max(Screen('Screens'))  
 [w, screenRect]=Screen('OpenWindow', screenNumber, 0, [],32,2);  
 white=WhiteIndex(screenNumber);  
 black=BlackIndex(screenNumber);  
 gray=GrayIndex(screenNumber);  
 Screen('FillRect',w, black);  
 Screen('Flip',w);  
  
 [x,y]=WindowCenter(w);  
 [b,h]=WindowSize(w);  
  
 Screen('TextFont',w, 'Courier');  
 Screen('TextSize',w, 50);  
 Screen('TextStyle', w, 0);  
  
 % draw something  
 for i=1:100  
 fromH=randperm(b);  
 fromH=fromH(1);  
 fromV=randperm(h);  
 fromV=fromV(1);  
 toH=randperm(b);  
 toH=toH(1);  
 toV=randperm(h);  
 toV=toV(1);  
 Screen('DrawLine', w, white, fromH,fromV, toH, toV ,8);  
 end  
 Screen('FillOval', w, [255 0 0], CenterRect(screenRect/4,   
screenRect));  
 %  
 mytext=['Screen ' num2str(screenNumber)];  
 [normBoundsRect, offsetBoundsRect]= Screen('TextBounds', w, mytext);  
 normBoundsRect=CenterRect(normBoundsRect,screenRect);  
 if usedrawtext==1  
 Screen('DrawText', w, mytext, normBoundsRect(1),   
normBoundsRect(4), white);  
 end  
  
 % we need to get the image before the flip  
 if usegetimage==1  
 imageArray=Screen('GetImage', w, [0 0 b h]);  
 else  
 imageArray=uint8(rand(round(b/4), round(h/4))\*255);  
 end  
 Screen('Flip',w);  
 WaitSecs(1);  
  
 mytex=Screen('MakeTexture', w, imageArray);  
  
 texRect=Screen('Rect', mytex);  
  
 % Screen('Flip',w);  
 % WaitSecs(1);  
 Screen('FillRect',w, black);  
 if usedrawtextafter==1  
 Screen('DrawText', w, mytext, normBoundsRect(1),   
normBoundsRect(4), white);  
 end  
  
 % WaitSecs(1);  
 fprintf('copy using drawtexture\n');  
 if 1  
 Screen('DrawTexture', w, mytex, texRect,   
CenterRect(screenRect/2, screenRect));  
 end  
  
 Screen('Flip',w);  
 WaitSecs(1);  
  
 Screen('FillRect',w, black);  
 Screen('Flip',w);  
 WaitSecs(1);  
  
 fprintf('copy using putimage\n');  
 if 1  
 Screen('PutImage', w, squeeze(imageArray),   
CenterRect(screenRect/2, screenRect));  
 % mytext='texture';  
 % Screen('DrawText', w, mytext, x/3, y/3, black);  
 end  
  
 Screen('Flip',w);  
 WaitSecs(1);  
  
 Screen('FillRect',w, black);  
 Screen('Flip',w);  
 WaitSecs(1);  
  
 Screen('CloseAll');  
  
 fprintf('\nEnd of demo.\n');  
catch  
 %this "catch" section executes in case of an error in the "try"   
section  
 %above. Importantly, it closes the onscreen window if its open.  
 % pnet('closeall');  
 Screen('CloseAll'); rethrow(lasterror);  
end %try..catch..
