I am encountering a problem trying to MATLAB compile a stimuli presentation program. It runs on MATLAB, but when I try to compile it I encounter an error:
The file 'C:\Program Files (x86)\MATLAB\toolbox\Psychtoolbox\PsychHardware\BrightSideDisplay\BrightSideCore.mexw32' appears to be a MEX-file. It shadows the M-file 'C:\Program Files (x86)\MATLAB\toolbox\Psychtoolbox\PsychHardware\BrightSideDisplay\BrightSideCore.m' but will not execute properly at runtime, as it does not export a function named 'mexFunction.'
I have tried compiling it on 2 different desktops and a laptop (running on MATLAB 2009b and PTB-3 in Windows 7) but I still get the same problem.
I have looked extensively on forums and online and have tried some workarounds suggested. I have done the following but the problem still remains:
1) One suggestion was to delete the 'mexw32' file (section 4.3.4 of http://docs.mosek.com/6.0/toolbox/node006.html#227582464
). While doing this allowed me to compile the code into a standalone exe, the executable crashes when I run it.
2) I did a search on MATLAB/PTB documentation for 'BrightSide' (http://docs.psychtoolbox.org/BrightSideDisplay) and found the following documentation (http://docs.psychtoolbox.org/BSRuntimeLibs) that instruct me to install library files from a company called BrightSide Technologies (MATLAB and Psychtoolbox cannot provide the files due to licencing issues). However, while I could locate most of these files online and from the computer, the first 2 files cannot be located (GL_OutputLibrary.dll and CoreLibrary_GL.dll). Upon further research I have come to the conclusion that Bright Side Technologies has since been overtaken by Dolby, so the files do not exist anymore.
I have looked everywhere to get a better understanding of the problem with no success and I am at a loss. I also ran 'PerceptualVBLSyncTest' and 'VBLSyncTest' on MATLAB but could not see any issues. As this type of compiling error is beyond my skills, I would like to seek your technical expertise to help resolve this issue.
Here is the code:
function AOC_interleaved3
%
% Press escape key to abort demo, space key to toggle modes of specific
% algorithms.
%
% 'stereoMode' specifies the type of stereo display algorithm to use:
%
% 0 == Mono display - No stereo at all.
% 100 == Interleaved line stereo: Left eye image is displayed in even
% scanlines, right eye image is displayed in odd scanlines.
%Screen('Preference', 'SkipSyncTests', 1);
stereoMode=100;
size = (295.8354+295.8354)/2;
gratingsize = size*2; %551 is double of 275.5 roundedup. 275.5 is the average of width/height VA. By default the visible grating is 400 pixels by 400 pixels in size:
texsize=size;%gratingsize / 2;% Define Half-Size of the grating image (i.e. radius).
drawmask=1;% By default, we mask the grating by a gaussian transparency mask:
f_left=8/gratingsize;% Grating frequency in cycles/pixel: By default 0.05 cycles per pixel.
f_right=16/gratingsize;% Grating frequency in cycles/pixel: By default 0.05 cycles per pixel.
cyclespersecond = 2.9;% Speed of grating in cycles per second: 1 cycle per second by default.
angle=270;% Angle of the grating: We default to 30 degrees.
% This script calls Psychtoolbox commands available only in OpenGL-based
% versions of the Psychtoolbox. (So far, the OS X Psychtoolbox is the
% only OpenGL-base Psychtoolbox.) The Psychtoolbox command AssertPsychOpenGL will issue
% an error message if someone tries to execute this script on a computer without
% an OpenGL Psychtoolbox
AssertOpenGL;
try
% Get the list of Screens and choose the one with the highest screen number.
% Screen 0 is, by definition, the display with the menu bar. Often when
% two monitors are connected the one without the menu bar is used as
% the stimulus display. Chosing the display with the highest dislay number is
% a best guess about where you want the stimulus displayed.
scrnNum = max(Screen('Screens'));
white=WhiteIndex(scrnNum);
black=BlackIndex(scrnNum);
% Round gray to integral number, to avoid roundoff artifacts with some
% graphics cards:
gray=round((white+black)/2);
% This makes sure that on floating point framebuffers we still get a
% well defined gray. It isn't strictly neccessary in this demo:
if gray == white
gray=white / 2;
end
% Contrast 'inc'rement range for given white and gray values:
inc=white-gray;
% Prepare pipeline for configuration. This marks the start of a list of
% requirements/tasks to be met/executed in the pipeline:
PsychImaging('PrepareConfiguration');
PsychImaging('AddTask', 'General', 'InterleavedLineStereo', 0);
% Consolidate the list of requirements (error checking etc.), open a
% suitable onscreen window and configure the imaging pipeline for that
% window according to our specs. The syntax is the same as for
% Screen('OpenWindow'):
[windowPtr, windowRect]=PsychImaging('OpenWindow', scrnNum, 0, [], [], [], stereoMode);
%Obtain width & height of screen
[width, height] = WindowSize(windowPtr);
% Initially fill left- and right-eye image buffer with black background
% color:
Screen('SelectStereoDrawBuffer', windowPtr, 0);
Screen('FillRect', windowPtr, BlackIndex(scrnNum));
Screen('SelectStereoDrawBuffer', windowPtr, 1);
Screen('FillRect', windowPtr, BlackIndex(scrnNum));
% Show cleared start screen:
Screen('Flip', windowPtr);
% Set up alpha-blending for smooth (anti-aliased) drawing of dots:
Screen('BlendFunction', windowPtr, 'GL_SRC_ALPHA', 'GL_ONE_MINUS_SRC_ALPHA');
i = 1;
keyIsDown = 0;
Screen('Flip', windowPtr);
%% Calculate parameters of the left grating
% First we compute pixels per cycle, rounded up to full pixels, as we
% need this to create a grating of proper size below:
p_left=ceil(1/f_left); % default is 74
% Also need frequency in radians:
fr_left=f_left*2*pi; % default is 0.0850
% This is the visible size of the grating. It is twice the half-width
% of the texture plus one pixel to make sure it has an odd number of
% pixels and is therefore symmetric around the center of the texture:
visiblesize=2*texsize+1;
% Create one single static grating image:
%
% We only need a texture with a single row of pixels(i.e. 1 pixel in height) to
% define the whole grating! If the 'srcRect' in the 'Drawtexture' call
% below is "higher" than that (i.e. visibleSize >> 1), the GPU will
% automatically replicate pixel rows. This 1 pixel height saves memory
% and memory bandwith, ie. it is potentially faster on some GPUs.
%
% However it does need 2 * texsize + p columns, i.e. the visible size
% of the grating extended by the length of 1 period (repetition) of the
% sine-wave in pixels 'p':
x_left = meshgrid(-texsize:texsize + p_left, 1);
% Compute actual square-wave grating:
grating_left=gray + inc*floor(cos(fr_left*x_left+1)); %gray + inc*cos(fr*x);
% Store 1-D single row grating in texture:
gratingtex_left=Screen('MakeTexture', windowPtr, grating_left);
% Create a single gaussian transparency mask and store it to a texture:
% The mask must have the same size as the visible size of the grating
% to fully cover it. Here we must define it in 2 dimensions and can't
% get easily away with one single row of pixels.
%
% We create a two-layer texture: One unused luminance channel which we
% just fill with the same color as the background color of the screen
% 'gray'. The transparency (aka alpha) channel is filled with a
% gaussian (exp()) aperture mask:
mask=ones(2*texsize+1, 2*texsize+1, 2) * gray;
[x,y]=meshgrid(-1*texsize:1*texsize,-1*texsize:1*texsize);
mask(:, :, 2)=0;%white * (1 - exp(-((x/90).^2)-((y/90).^2)));
masktex=Screen('MakeTexture', windowPtr, mask);
%% Calculate parameters of the right grating
% First we compute pixels per cycle, rounded up to full pixels, as we
% need this to create a grating of proper size below:
p_right=ceil(1/f_right);
% Also need frequency in radians:
fr_right=f_right*2*pi;
% This is the visible size of the grating. It is twice the half-width
% of the texture plus one pixel to make sure it has an odd number of
% pixels and is therefore symmetric around the center of the texture:
visiblesize=2*texsize+1;
% Create one single static grating image:
%
% We only need a texture with a single row of pixels(i.e. 1 pixel in height) to
% define the whole grating! If the 'srcRect' in the 'Drawtexture' call
% below is "higher" than that (i.e. visibleSize >> 1), the GPU will
% automatically replicate pixel rows. This 1 pixel height saves memory
% and memory bandwith, ie. it is potentially faster on some GPUs.
%
% However it does need 2 * texsize + p columns, i.e. the visible size
% of the grating extended by the length of 1 period (repetition) of the
% sine-wave in pixels 'p':
x_right = meshgrid(-texsize:texsize + p_right, 1);
% Compute actual square-wave grating:
grating_right=gray + inc*floor(cos(fr_right*x_right+1)); %gray + inc*cos(fr*x);
% Store 1-D single row grating in texture:
gratingtex_right=Screen('MakeTexture', windowPtr, grating_right);
% Create a single gaussian transparency mask and store it to a texture:
% The mask must have the same size as the visible size of the grating
% to fully cover it. Here we must define it in 2 dimensions and can't
% get easily away with one single row of pixels.
%
% We create a two-layer texture: One unused luminance channel which we
% just fill with the same color as the background color of the screen
% 'gray'. The transparency (aka alpha) channel is filled with a
% gaussian (exp()) aperture mask:
mask=ones(2*texsize+1, 2*texsize+1, 2) * gray;
[x,y]=meshgrid(-1*texsize:1*texsize,-1*texsize:1*texsize);
mask(:, :, 2)=0;%white * (1 - exp(-((x/90).^2)-((y/90).^2)));
masktex=Screen('MakeTexture', windowPtr, mask);
%%
% Query maximum useable priorityLevel on this system:
priorityLevel=MaxPriority(windowPtr); %priority set to 1
% We don't use Priority() in order to not accidentally overload older
% machines that can't handle a redraw every 40 ms. If your machine is
% fast enough, uncomment this to get more accurate timing.
Priority(priorityLevel);
% Definition of the drawn rectangle on the screen:
% Compute it to be the visible size of the grating, centered on the
% screen:
dstRect=[0 0 visiblesize visiblesize];
dstRect=CenterRect(dstRect, windowRect);
% Query duration of one monitor refresh interval:
ifi=Screen('GetFlipInterval', windowPtr);
waitframes = 1;
% Translate frames into seconds for screen update interval:
waitduration = waitframes * ifi;
% Recompute p, this time without the ceil() operation from above.
% Otherwise we will get wrong drift speed due to rounding errors!
p=1/f_left; % pixels/cycle
% Translate requested speed of the grating (in cycles per second) into
% a shift value in "pixels per frame", for given waitduration: This is
% the amount of pixels to shift our srcRect "aperture" in horizontal
% directionat each redraw:
shiftperframe= cyclespersecond * p * waitduration;
% Perform initial Flip to sync us to the VBL and for getting an initial
% VBL-Timestamp as timing baseline for our redraw loop:
vbl=Screen('Flip', windowPtr);
%destinationRect for the 2 gratings
dstRect1 = [(width/2) - (texsize/2), (height/2) - (texsize/4), (width/2) + (texsize/2), (height/2) + (texsize/4)];
dstRect2 = [(width/2) - (texsize/2), (height/2) - (texsize/2), (width/2) + (texsize/2), (height/2) + (texsize/2)];
%destinationRect to fill the screen
dstRect_fillscreen = [0,0,width,height];
%Set index for drifting
i=0;
% Perform a flip to sync us to vbl and take start-timestamp in t:
t = Screen('Flip', windowPtr);
HideCursor;
% Run until a key is pressed:
while ~KbCheck%length(t) < nmax
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Draw the grating
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
xoffset = mod(i*shiftperframe,p);
i=i+1;
srcRect=[xoffset 0 xoffset + visiblesize visiblesize];
%%%%%%%%%%%%%%%%%
% Draw left stim
%%%%%%%%%%%%%%%%%
% Disable alpha-blending, restrict following drawing to alpha channel:
Screen('Blendfunction', windowPtr, GL_ONE, GL_ZERO, [0 0 0 1]);
% Select left-eye image buffer for drawing:
Screen('SelectStereoDrawBuffer', windowPtr, 1);
% Clear 'dstRect' region of framebuffers alpha channel to zero:
Screen('FillRect', windowPtr, [0 0 0 0], dstRect_fillscreen);
% Fill circular 'dstRect' region with an alpha value of 255:
Screen('FillOval', windowPtr, [0 0 0 255], dstRect1);
Screen('Blendfunction', windowPtr, GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA, [1 1 1 1]);
Screen('DrawTexture', windowPtr, gratingtex_left, srcRect, dstRect1, 180, [], [], [0 255 0]); %draw left vertical grating
% Restore alpha blending mode for next draw iteration:
Screen('Blendfunction', windowPtr, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
%%%%%%%%%%%%%%%%%
% Draw right stim
%%%%%%%%%%%%%%%%%
% Disable alpha-blending, restrict following drawing to alpha channel:
Screen('Blendfunction', windowPtr, GL_ONE, GL_ZERO, [0 0 0 1]);
% Select left-eye image buffer for drawing:
Screen('SelectStereoDrawBuffer', windowPtr, 0);
% Clear 'dstRect' region of framebuffers alpha channel to zero:
Screen('FillRect', windowPtr, [0 0 0 0], dstRect_fillscreen);
% Fill circular 'dstRect' region with an alpha value of 255:
Screen('FillOval', windowPtr, [0 0 0 255], dstRect1);
Screen('Blendfunction', windowPtr, GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA, [1 1 1 1]);
Screen('DrawTexture', windowPtr, gratingtex_right, srcRect, dstRect2, 270, [], [], [0 255 0]); %draw left vertical grating
% Restore alpha blending mode for next draw iteration:
Screen('Blendfunction', windowPtr, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
% Tell PTB drawing is finished for this frame:
Screen('DrawingFinished', windowPtr);
% Flip stim to display and take timestamp of stimulus-onset after
% displaying the new stimulus and record it in vector t:
%onset = Screen('Flip', windowPtr);
%t = [t onset];
%vbl = Screen('Flip', windowPtr, vbl + (waitframes - 0.5) * ifi);
vbl = Screen('Flip', windowPtr);
end
% Last Flip:
Screen('Flip', windowPtr);
ShowCursor;
% Done. Close the onscreen window:
Screen('CloseAll')
% We're done.
clearall;
return;
catch
% Executes in case of an error: Closes onscreen window:
Screen('CloseAll');
psychrethrow(psychlasterror);
end;
Any assistance would be much appreciated.
The file 'C:\Program Files (x86)\MATLAB\toolbox\Psychtoolbox\PsychHardware\BrightSideDisplay\BrightSideCore.mexw32' appears to be a MEX-file. It shadows the M-file 'C:\Program Files (x86)\MATLAB\toolbox\Psychtoolbox\PsychHardware\BrightSideDisplay\BrightSideCore.m' but will not execute properly at runtime, as it does not export a function named 'mexFunction.'
I have tried compiling it on 2 different desktops and a laptop (running on MATLAB 2009b and PTB-3 in Windows 7) but I still get the same problem.
I have looked extensively on forums and online and have tried some workarounds suggested. I have done the following but the problem still remains:
1) One suggestion was to delete the 'mexw32' file (section 4.3.4 of http://docs.mosek.com/6.0/toolbox/node006.html#227582464
). While doing this allowed me to compile the code into a standalone exe, the executable crashes when I run it.
2) I did a search on MATLAB/PTB documentation for 'BrightSide' (http://docs.psychtoolbox.org/BrightSideDisplay) and found the following documentation (http://docs.psychtoolbox.org/BSRuntimeLibs) that instruct me to install library files from a company called BrightSide Technologies (MATLAB and Psychtoolbox cannot provide the files due to licencing issues). However, while I could locate most of these files online and from the computer, the first 2 files cannot be located (GL_OutputLibrary.dll and CoreLibrary_GL.dll). Upon further research I have come to the conclusion that Bright Side Technologies has since been overtaken by Dolby, so the files do not exist anymore.
I have looked everywhere to get a better understanding of the problem with no success and I am at a loss. I also ran 'PerceptualVBLSyncTest' and 'VBLSyncTest' on MATLAB but could not see any issues. As this type of compiling error is beyond my skills, I would like to seek your technical expertise to help resolve this issue.
Here is the code:
function AOC_interleaved3
%
% Press escape key to abort demo, space key to toggle modes of specific
% algorithms.
%
% 'stereoMode' specifies the type of stereo display algorithm to use:
%
% 0 == Mono display - No stereo at all.
% 100 == Interleaved line stereo: Left eye image is displayed in even
% scanlines, right eye image is displayed in odd scanlines.
%Screen('Preference', 'SkipSyncTests', 1);
stereoMode=100;
size = (295.8354+295.8354)/2;
gratingsize = size*2; %551 is double of 275.5 roundedup. 275.5 is the average of width/height VA. By default the visible grating is 400 pixels by 400 pixels in size:
texsize=size;%gratingsize / 2;% Define Half-Size of the grating image (i.e. radius).
drawmask=1;% By default, we mask the grating by a gaussian transparency mask:
f_left=8/gratingsize;% Grating frequency in cycles/pixel: By default 0.05 cycles per pixel.
f_right=16/gratingsize;% Grating frequency in cycles/pixel: By default 0.05 cycles per pixel.
cyclespersecond = 2.9;% Speed of grating in cycles per second: 1 cycle per second by default.
angle=270;% Angle of the grating: We default to 30 degrees.
% This script calls Psychtoolbox commands available only in OpenGL-based
% versions of the Psychtoolbox. (So far, the OS X Psychtoolbox is the
% only OpenGL-base Psychtoolbox.) The Psychtoolbox command AssertPsychOpenGL will issue
% an error message if someone tries to execute this script on a computer without
% an OpenGL Psychtoolbox
AssertOpenGL;
try
% Get the list of Screens and choose the one with the highest screen number.
% Screen 0 is, by definition, the display with the menu bar. Often when
% two monitors are connected the one without the menu bar is used as
% the stimulus display. Chosing the display with the highest dislay number is
% a best guess about where you want the stimulus displayed.
scrnNum = max(Screen('Screens'));
white=WhiteIndex(scrnNum);
black=BlackIndex(scrnNum);
% Round gray to integral number, to avoid roundoff artifacts with some
% graphics cards:
gray=round((white+black)/2);
% This makes sure that on floating point framebuffers we still get a
% well defined gray. It isn't strictly neccessary in this demo:
if gray == white
gray=white / 2;
end
% Contrast 'inc'rement range for given white and gray values:
inc=white-gray;
% Prepare pipeline for configuration. This marks the start of a list of
% requirements/tasks to be met/executed in the pipeline:
PsychImaging('PrepareConfiguration');
PsychImaging('AddTask', 'General', 'InterleavedLineStereo', 0);
% Consolidate the list of requirements (error checking etc.), open a
% suitable onscreen window and configure the imaging pipeline for that
% window according to our specs. The syntax is the same as for
% Screen('OpenWindow'):
[windowPtr, windowRect]=PsychImaging('OpenWindow', scrnNum, 0, [], [], [], stereoMode);
%Obtain width & height of screen
[width, height] = WindowSize(windowPtr);
% Initially fill left- and right-eye image buffer with black background
% color:
Screen('SelectStereoDrawBuffer', windowPtr, 0);
Screen('FillRect', windowPtr, BlackIndex(scrnNum));
Screen('SelectStereoDrawBuffer', windowPtr, 1);
Screen('FillRect', windowPtr, BlackIndex(scrnNum));
% Show cleared start screen:
Screen('Flip', windowPtr);
% Set up alpha-blending for smooth (anti-aliased) drawing of dots:
Screen('BlendFunction', windowPtr, 'GL_SRC_ALPHA', 'GL_ONE_MINUS_SRC_ALPHA');
i = 1;
keyIsDown = 0;
Screen('Flip', windowPtr);
%% Calculate parameters of the left grating
% First we compute pixels per cycle, rounded up to full pixels, as we
% need this to create a grating of proper size below:
p_left=ceil(1/f_left); % default is 74
% Also need frequency in radians:
fr_left=f_left*2*pi; % default is 0.0850
% This is the visible size of the grating. It is twice the half-width
% of the texture plus one pixel to make sure it has an odd number of
% pixels and is therefore symmetric around the center of the texture:
visiblesize=2*texsize+1;
% Create one single static grating image:
%
% We only need a texture with a single row of pixels(i.e. 1 pixel in height) to
% define the whole grating! If the 'srcRect' in the 'Drawtexture' call
% below is "higher" than that (i.e. visibleSize >> 1), the GPU will
% automatically replicate pixel rows. This 1 pixel height saves memory
% and memory bandwith, ie. it is potentially faster on some GPUs.
%
% However it does need 2 * texsize + p columns, i.e. the visible size
% of the grating extended by the length of 1 period (repetition) of the
% sine-wave in pixels 'p':
x_left = meshgrid(-texsize:texsize + p_left, 1);
% Compute actual square-wave grating:
grating_left=gray + inc*floor(cos(fr_left*x_left+1)); %gray + inc*cos(fr*x);
% Store 1-D single row grating in texture:
gratingtex_left=Screen('MakeTexture', windowPtr, grating_left);
% Create a single gaussian transparency mask and store it to a texture:
% The mask must have the same size as the visible size of the grating
% to fully cover it. Here we must define it in 2 dimensions and can't
% get easily away with one single row of pixels.
%
% We create a two-layer texture: One unused luminance channel which we
% just fill with the same color as the background color of the screen
% 'gray'. The transparency (aka alpha) channel is filled with a
% gaussian (exp()) aperture mask:
mask=ones(2*texsize+1, 2*texsize+1, 2) * gray;
[x,y]=meshgrid(-1*texsize:1*texsize,-1*texsize:1*texsize);
mask(:, :, 2)=0;%white * (1 - exp(-((x/90).^2)-((y/90).^2)));
masktex=Screen('MakeTexture', windowPtr, mask);
%% Calculate parameters of the right grating
% First we compute pixels per cycle, rounded up to full pixels, as we
% need this to create a grating of proper size below:
p_right=ceil(1/f_right);
% Also need frequency in radians:
fr_right=f_right*2*pi;
% This is the visible size of the grating. It is twice the half-width
% of the texture plus one pixel to make sure it has an odd number of
% pixels and is therefore symmetric around the center of the texture:
visiblesize=2*texsize+1;
% Create one single static grating image:
%
% We only need a texture with a single row of pixels(i.e. 1 pixel in height) to
% define the whole grating! If the 'srcRect' in the 'Drawtexture' call
% below is "higher" than that (i.e. visibleSize >> 1), the GPU will
% automatically replicate pixel rows. This 1 pixel height saves memory
% and memory bandwith, ie. it is potentially faster on some GPUs.
%
% However it does need 2 * texsize + p columns, i.e. the visible size
% of the grating extended by the length of 1 period (repetition) of the
% sine-wave in pixels 'p':
x_right = meshgrid(-texsize:texsize + p_right, 1);
% Compute actual square-wave grating:
grating_right=gray + inc*floor(cos(fr_right*x_right+1)); %gray + inc*cos(fr*x);
% Store 1-D single row grating in texture:
gratingtex_right=Screen('MakeTexture', windowPtr, grating_right);
% Create a single gaussian transparency mask and store it to a texture:
% The mask must have the same size as the visible size of the grating
% to fully cover it. Here we must define it in 2 dimensions and can't
% get easily away with one single row of pixels.
%
% We create a two-layer texture: One unused luminance channel which we
% just fill with the same color as the background color of the screen
% 'gray'. The transparency (aka alpha) channel is filled with a
% gaussian (exp()) aperture mask:
mask=ones(2*texsize+1, 2*texsize+1, 2) * gray;
[x,y]=meshgrid(-1*texsize:1*texsize,-1*texsize:1*texsize);
mask(:, :, 2)=0;%white * (1 - exp(-((x/90).^2)-((y/90).^2)));
masktex=Screen('MakeTexture', windowPtr, mask);
%%
% Query maximum useable priorityLevel on this system:
priorityLevel=MaxPriority(windowPtr); %priority set to 1
% We don't use Priority() in order to not accidentally overload older
% machines that can't handle a redraw every 40 ms. If your machine is
% fast enough, uncomment this to get more accurate timing.
Priority(priorityLevel);
% Definition of the drawn rectangle on the screen:
% Compute it to be the visible size of the grating, centered on the
% screen:
dstRect=[0 0 visiblesize visiblesize];
dstRect=CenterRect(dstRect, windowRect);
% Query duration of one monitor refresh interval:
ifi=Screen('GetFlipInterval', windowPtr);
waitframes = 1;
% Translate frames into seconds for screen update interval:
waitduration = waitframes * ifi;
% Recompute p, this time without the ceil() operation from above.
% Otherwise we will get wrong drift speed due to rounding errors!
p=1/f_left; % pixels/cycle
% Translate requested speed of the grating (in cycles per second) into
% a shift value in "pixels per frame", for given waitduration: This is
% the amount of pixels to shift our srcRect "aperture" in horizontal
% directionat each redraw:
shiftperframe= cyclespersecond * p * waitduration;
% Perform initial Flip to sync us to the VBL and for getting an initial
% VBL-Timestamp as timing baseline for our redraw loop:
vbl=Screen('Flip', windowPtr);
%destinationRect for the 2 gratings
dstRect1 = [(width/2) - (texsize/2), (height/2) - (texsize/4), (width/2) + (texsize/2), (height/2) + (texsize/4)];
dstRect2 = [(width/2) - (texsize/2), (height/2) - (texsize/2), (width/2) + (texsize/2), (height/2) + (texsize/2)];
%destinationRect to fill the screen
dstRect_fillscreen = [0,0,width,height];
%Set index for drifting
i=0;
% Perform a flip to sync us to vbl and take start-timestamp in t:
t = Screen('Flip', windowPtr);
HideCursor;
% Run until a key is pressed:
while ~KbCheck%length(t) < nmax
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Draw the grating
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
xoffset = mod(i*shiftperframe,p);
i=i+1;
srcRect=[xoffset 0 xoffset + visiblesize visiblesize];
%%%%%%%%%%%%%%%%%
% Draw left stim
%%%%%%%%%%%%%%%%%
% Disable alpha-blending, restrict following drawing to alpha channel:
Screen('Blendfunction', windowPtr, GL_ONE, GL_ZERO, [0 0 0 1]);
% Select left-eye image buffer for drawing:
Screen('SelectStereoDrawBuffer', windowPtr, 1);
% Clear 'dstRect' region of framebuffers alpha channel to zero:
Screen('FillRect', windowPtr, [0 0 0 0], dstRect_fillscreen);
% Fill circular 'dstRect' region with an alpha value of 255:
Screen('FillOval', windowPtr, [0 0 0 255], dstRect1);
Screen('Blendfunction', windowPtr, GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA, [1 1 1 1]);
Screen('DrawTexture', windowPtr, gratingtex_left, srcRect, dstRect1, 180, [], [], [0 255 0]); %draw left vertical grating
% Restore alpha blending mode for next draw iteration:
Screen('Blendfunction', windowPtr, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
%%%%%%%%%%%%%%%%%
% Draw right stim
%%%%%%%%%%%%%%%%%
% Disable alpha-blending, restrict following drawing to alpha channel:
Screen('Blendfunction', windowPtr, GL_ONE, GL_ZERO, [0 0 0 1]);
% Select left-eye image buffer for drawing:
Screen('SelectStereoDrawBuffer', windowPtr, 0);
% Clear 'dstRect' region of framebuffers alpha channel to zero:
Screen('FillRect', windowPtr, [0 0 0 0], dstRect_fillscreen);
% Fill circular 'dstRect' region with an alpha value of 255:
Screen('FillOval', windowPtr, [0 0 0 255], dstRect1);
Screen('Blendfunction', windowPtr, GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA, [1 1 1 1]);
Screen('DrawTexture', windowPtr, gratingtex_right, srcRect, dstRect2, 270, [], [], [0 255 0]); %draw left vertical grating
% Restore alpha blending mode for next draw iteration:
Screen('Blendfunction', windowPtr, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
% Tell PTB drawing is finished for this frame:
Screen('DrawingFinished', windowPtr);
% Flip stim to display and take timestamp of stimulus-onset after
% displaying the new stimulus and record it in vector t:
%onset = Screen('Flip', windowPtr);
%t = [t onset];
%vbl = Screen('Flip', windowPtr, vbl + (waitframes - 0.5) * ifi);
vbl = Screen('Flip', windowPtr);
end
% Last Flip:
Screen('Flip', windowPtr);
ShowCursor;
% Done. Close the onscreen window:
Screen('CloseAll')
% We're done.
clearall;
return;
catch
% Executes in case of an error: Closes onscreen window:
Screen('CloseAll');
psychrethrow(psychlasterror);
end;
Any assistance would be much appreciated.