Error using DrawTexture

Hi,

I'm having trouble with a script when trying to use DrawTexture.

I keep getting the error message below:

displaycommand = Screen('DrawTexture',w,imagetex(i),[],pRect{i});

Error in function DrawTexture: Invalid Window (or Texture) Index provided: It doesn't correspond to an open window or texture.
Did you close it accidentally via Screen('Close') or Screen('CloseAll') ?
??? Error using ==> Screen
Usage:

Screen('DrawTexture', windowPointer, texturePointer [,sourceRect] [,destinationRect] [,rotationAngle] [,
filterMode] [, globalAlpha] [, modulateColor] [, textureShader] [, specialFlags] [, auxParameters]);

Error in ==> MSS_test at 654
eval(displaycommand);

Nowhere in the script is there a Screen('Close').

Here is the script I think the error message is referring to :

% setup text to be displayed (as written, will center text and
% wrap at default_wrap pixels)
displaycommand = sprintf('DrawFormattedText_new(w,stFile{i},''center'', ''center'',black, default_wrap,hshift(i),vshift(i));');

elseif st(i) == 's' %primary stimulus is sound
eval(bg_display); %present the background file while sound is playing
Screen('Flip',w);

t1 = GetSecs;

% Open the default audio device [], with default mode [] (==Only playback),
% and a required latencyclass of zero 0 == no low-latency mode, as well as
% a frequency of stSoundList{i,2} = fs, and nrchannels sound channels.
% This returns a handle to the audio device:
pahandle = PsychPortAudio('Open', [], [], 1, stSoundList{i,2},nrchannels);

% Fill the audio playback buffer with the audio data 'stSoundList{i,1} = x from above':
PsychPortAudio('FillBuffer', pahandle, stSoundList{i,1}');
t2 = GetSecs;

if DEBUG
fprintf( 'It took %f seconds to open PsychPortAudio and fill the buffer in iteration %d\n',t2-t1,i);
end

% Start audio playback for 'repetitions' repetitions of the sound data,
% start it immediately (0) and wait for the playback to start, return onset
% timestamp.
t1 = PsychPortAudio('Start', pahandle, rep(i), 0, 1);
onset(i) = t1 - experiment_start_time; %sound onset
sound_closed = 0;

displaycommand = bg_display; %For sound, foreground and background images are same

elseif st(i) == 'p' %primary stimulus is a picture
displaycommand = sprintf('Screen(''DrawTexture'',w,imagetex(i),[],pRect{i});');
end; % if st(i)

if DEBUG
fprintf('\ni= %d,\nst(i) = %c\n',i, st(i));
fprintf('displaycommand = %s\n\n',displaycommand);
end;


%%%%%%%%%%%%%%%%%%%%%%%
%Put stimuli on screen
%%%%%%%%%%%%%%%%%%%%%%%

t1 = GetSecs;
eval(displaycommand);
[vbltime,start_time]=Screen('Flip',w);
t2 = GetSecs;
fprintf('We needed %f seconds to Draw texture %d.\n',t2-t1,i)


Also, I am using a Windows 7 machine with Matlab 2009b in 32-bit and Psychtoolbox 3.

Any help is appreciated.

Sonia
you need to use Screen('MakeTexture') to create the texture before drawing it. See Screen'MakeTexture?') for help


On Sat, Aug 17, 2013 at 3:13 AM, soniakrol <soniakrol@...> wrote:

Hi,

I'm having trouble with a script when trying to use DrawTexture.

I keep getting the error message below:

displaycommand = Screen('DrawTexture',w,imagetex(i),[],pRect{i});

Error in function DrawTexture: Invalid Window (or Texture) Index provided: It doesn't correspond to an open window or texture.
Did you close it accidentally via Screen('Close') or Screen('CloseAll') ?
??? Error using ==> Screen
Usage:

Screen('DrawTexture', windowPointer, texturePointer [,sourceRect] [,destinationRect] [,rotationAngle] [,
filterMode] [, globalAlpha] [, modulateColor] [, textureShader] [, specialFlags] [, auxParameters]);

Error in ==> MSS_test at 654
eval(displaycommand);

Nowhere in the script is there a Screen('Close').

Here is the script I think the error message is referring to :

% setup text to be displayed (as written, will center text and
% wrap at default_wrap pixels)
displaycommand = sprintf('DrawFormattedText_new(w,stFile{i},''center'', ''center'',black, default_wrap,hshift(i),vshift(i));');

elseif st(i) == 's' %primary stimulus is sound
eval(bg_display); %present the background file while sound is playing
Screen('Flip',w);

t1 = GetSecs;

% Open the default audio device [], with default mode [] (==Only playback),
% and a required latencyclass of zero 0 == no low-latency mode, as well as
% a frequency of stSoundList{i,2} = fs, and nrchannels sound channels.
% This returns a handle to the audio device:
pahandle = PsychPortAudio('Open', [], [], 1, stSoundList{i,2},nrchannels);

% Fill the audio playback buffer with the audio data 'stSoundList{i,1} = x from above':
PsychPortAudio('FillBuffer', pahandle, stSoundList{i,1}');
t2 = GetSecs;

if DEBUG
fprintf( 'It took %f seconds to open PsychPortAudio and fill the buffer in iteration %d\n',t2-t1,i);
end

% Start audio playback for 'repetitions' repetitions of the sound data,
% start it immediately (0) and wait for the playback to start, return onset
% timestamp.
t1 = PsychPortAudio('Start', pahandle, rep(i), 0, 1);
onset(i) = t1 - experiment_start_time; %sound onset
sound_closed = 0;

displaycommand = bg_display; %For sound, foreground and background images are same

elseif st(i) == 'p' %primary stimulus is a picture
displaycommand = sprintf('Screen(''DrawTexture'',w,imagetex(i),[],pRect{i});');
end; % if st(i)

if DEBUG
fprintf('\ni= %d,\nst(i) = %c\n',i, st(i));
fprintf('displaycommand = %s\n\n',displaycommand);
end;

%%%%%%%%%%%%%%%%%%%%%%%
%Put stimuli on screen
%%%%%%%%%%%%%%%%%%%%%%%

t1 = GetSecs;
eval(displaycommand);
[vbltime,start_time]=Screen('Flip',w);
t2 = GetSecs;
fprintf('We needed %f seconds to Draw texture %d.\n',t2-t1,i)

Also, I am using a Windows 7 machine with Matlab 2009b in 32-bit and Psychtoolbox 3.

Any help is appreciated.

Sonia