Using LoadNormalizeGammaTable fails

Hi,

We met a problem when using LoadNormalizeGammaTable. LoadNormalizeGammaTable fails when used for the first time in our demo.When we run the demo,there is always a full contrast square shows and disappears quickly at the beginning of Animationloop(acctually there should be a low contrast square ), then LoadNormalizeGammaTable becomes normal.
This happens on both Windows and Mac.Is there something wrong with the code? Any ideas to avoid this?
Many thanks!

Here is the demo:

clear all;clc;
KbName('UnifyKeyNames');
global monitor w Tpress;
oldEnableFlag = Screen('Preference', 'TextAntiAliasing', 0);
dur = 60; % how long we show the demo
fixSiz = 12; % size of the fixation point
try
AssertOpenGL;
ncolors = 253;
screens = Screen('Screens');
screenNumber = max(screens);
bkgcol = ncolors/2;
[w, screenRect] = Screen('OpenWindow', screenNumber, ncolors/2);
monitor.center = CenterRect([0 0 1 1],screenRect);
fixpos = [monitor.center(1) monitor.center(2)];
monitor.oldclut = Screen('ReadNormalizedGammaTable',screenNumber);

Priority(MaxPriority(w));
HideCursor;

img = zeros(100,100);
tex = Screen('MakeTexture', w, img);
siz = size(img);

newcmap = gray(ncolors);
newclut=zeros(256,3);newclut(1:ncolors,:) = newcmap;
newclut(254:256,:) = [1 1 1;0 0 0;0 0 0]; % a lookup table for 100% contrast, though it is not calibrated.

newcmap=.5*ones(ncolors,3);
newclut2=zeros(256,3);newclut2(1:ncolors,:) = newcmap;
newclut2(254:256,:) = [1 1 1;0 0 0;0 0 0]; % a lookup table for 0% contrast.
Screen('FillRect',w,bkgcol);
Screen('DrawArc',w,255,CenterRect([0 0 fixSiz fixSiz],screenRect),0,360);
Screen('Flip',w);
Screen('LoadNormalizedGammaTable',w,newclut);

DrawFormattedText(w, 'Press a key to start', 'center','center');
Screen('Flip',w);
KbWait;

% Animationloop:
t0 = GetSecs;
Tpress = t0;
whichclut = 1;
while((GetSecs-t0) < dur)
Screen('DrawTexture',w,tex);
Screen('DrawArc', w, 255, CenterRect([0 0 fixSiz fixSiz], screenRect), 0, 360);
if whichclut == 1
Screen('DrawText', w, 'Contrast = 0%', 150, 150, 255);
else
Screen('DrawText', w, 'Contrast = 100%', 150, 150, 255);
end
Screen('Flip',w);
if whichclut == 1
Screen('LoadNormalizedGammaTable',w,newclut2);
else
Screen('LoadNormalizedGammaTable',w,newclut);
end
[keyIsDown, secs, keyCode, deltaSecs] = KbCheck;
if keyIsDown && GetSecs-Tpress > .2
if keyCode(KbName('q')) % press q to quit the programn
error('quit!');
else
whichclut = 3-whichclut; % otherwise the lookup table is altered.
end
Tpress = GetSecs;
end
end;
Screen('FillRect',w, bkgcol);
Screen('Flip', w);
Screen('LoadNormalizedGammaTable',w,monitor.oldclut);
Screen('Preference', 'TextAntiAliasing', oldEnableFlag);
Screen('CloseAll');
Priority(0);
ShowCursor;
catch ME
Screen('FillRect',w, bkgcol);
Screen('Flip', w);
Screen('LoadNormalizedGammaTable',w,monitor.oldclut);
Screen('Preference', 'TextAntiAliasing', oldEnableFlag);
Screen('CloseAll');
Priority(0);
ShowCursor;
psychrethrow(psychlasterror);
end
It behaves as it should, according to your script and our help, which you should have read. 'LoadNormalizedGammatable', depending on operating system and graphics card, will either update the gamma table immediately or at start of next video refresh cycle. As you issue the command after the 'Flip', first the flip will show your new stimulus image and then either shortly after, or 1 frame duration later, 'loadnormalizedgammatalbe' will take effect - hence the flash for up to 1 frame duration. The exact timing of the function is not guaranteed as this depends a lot on the operating system/driver/gpu.

Usually if you try to do what you try to do, you're doing it the wrong way.

-mario



--- In psychtoolbox@yahoogroups.com, "schnee_dx" wrote:
>
> Hi,
>
> We met a problem when using LoadNormalizeGammaTable. LoadNormalizeGammaTable fails when used for the first time in our demo.When we run the demo,there is always a full contrast square shows and disappears quickly at the beginning of Animationloop(acctually there should be a low contrast square ), then LoadNormalizeGammaTable becomes normal.
> This happens on both Windows and Mac.Is there something wrong with the code? Any ideas to avoid this?
> Many thanks!
>
> Here is the demo:
>
> clear all;clc;
> KbName('UnifyKeyNames');
> global monitor w Tpress;
> oldEnableFlag = Screen('Preference', 'TextAntiAliasing', 0);
> dur = 60; % how long we show the demo
> fixSiz = 12; % size of the fixation point
> try
> AssertOpenGL;
> ncolors = 253;
> screens = Screen('Screens');
> screenNumber = max(screens);
> bkgcol = ncolors/2;
> [w, screenRect] = Screen('OpenWindow', screenNumber, ncolors/2);
> monitor.center = CenterRect([0 0 1 1],screenRect);
> fixpos = [monitor.center(1) monitor.center(2)];
> monitor.oldclut = Screen('ReadNormalizedGammaTable',screenNumber);
>
> Priority(MaxPriority(w));
> HideCursor;
>
> img = zeros(100,100);
> tex = Screen('MakeTexture', w, img);
> siz = size(img);
>
> newcmap = gray(ncolors);
> newclut=zeros(256,3);newclut(1:ncolors,:) = newcmap;
> newclut(254:256,:) = [1 1 1;0 0 0;0 0 0]; % a lookup table for 100% contrast, though it is not calibrated.
>
> newcmap=.5*ones(ncolors,3);
> newclut2=zeros(256,3);newclut2(1:ncolors,:) = newcmap;
> newclut2(254:256,:) = [1 1 1;0 0 0;0 0 0]; % a lookup table for 0% contrast.
> Screen('FillRect',w,bkgcol);
> Screen('DrawArc',w,255,CenterRect([0 0 fixSiz fixSiz],screenRect),0,360);
> Screen('Flip',w);
> Screen('LoadNormalizedGammaTable',w,newclut);
>
> DrawFormattedText(w, 'Press a key to start', 'center','center');
> Screen('Flip',w);
> KbWait;
>
> % Animationloop:
> t0 = GetSecs;
> Tpress = t0;
> whichclut = 1;
> while((GetSecs-t0) < dur)
> Screen('DrawTexture',w,tex);
> Screen('DrawArc', w, 255, CenterRect([0 0 fixSiz fixSiz], screenRect), 0, 360);
> if whichclut == 1
> Screen('DrawText', w, 'Contrast = 0%', 150, 150, 255);
> else
> Screen('DrawText', w, 'Contrast = 100%', 150, 150, 255);
> end
> Screen('Flip',w);
> if whichclut == 1
> Screen('LoadNormalizedGammaTable',w,newclut2);
> else
> Screen('LoadNormalizedGammaTable',w,newclut);
> end
> [keyIsDown, secs, keyCode, deltaSecs] = KbCheck;
> if keyIsDown && GetSecs-Tpress > .2
> if keyCode(KbName('q')) % press q to quit the programn
> error('quit!');
> else
> whichclut = 3-whichclut; % otherwise the lookup table is altered.
> end
> Tpress = GetSecs;
> end
> end;
> Screen('FillRect',w, bkgcol);
> Screen('Flip', w);
> Screen('LoadNormalizedGammaTable',w,monitor.oldclut);
> Screen('Preference', 'TextAntiAliasing', oldEnableFlag);
> Screen('CloseAll');
> Priority(0);
> ShowCursor;
> catch ME
> Screen('FillRect',w, bkgcol);
> Screen('Flip', w);
> Screen('LoadNormalizedGammaTable',w,monitor.oldclut);
> Screen('Preference', 'TextAntiAliasing', oldEnableFlag);
> Screen('CloseAll');
> Priority(0);
> ShowCursor;
> psychrethrow(psychlasterror);
> end
>