function HolidaySnap2();
% HolidaySnap2();
%
% Example of displaying an image.
%
% This script
% - reads an image from a file
% - shows the image with accurate timing
% - draws a fixation spot
%
% Please refer to other demos in Psychtoolbox-3

%%%%%%%%%%%%%%%%%%%%%%%%%
% preliminary stuff
%%%%%%%%%%%%%%%%%%%%%%%%%

% Clear Matlab/Octave window:
clc;

% check for OpenGL compatibility, abort otherwise:
AssertOpenGL;


%%%%%%%%%%%%%%%%%%%%%%
% file handling
%%%%%%%%%%%%%%%%%%%%%%

% read stimulus image into matlab matrix 'imdata':
imdata=imread('HolidaySnap1.jpg');


%%%%%%%%%%%%%%%%%%%%%%
% image display
%%%%%%%%%%%%%%%%%%%%%%

% Embed core of code in try ... catch statement. If anything goes wrong
% inside the 'try' block (Matlab error), the 'catch' block is executed to
% clean up, save results, close the onscreen window etc.
try
    % Get screenNumber of stimulation display. We choose the display with
    % the maximum index, which is usually the right one, e.g., the external
    % display on a Laptop:
    screens=Screen('Screens');
    screenNumber=max(screens);
    
    % Hide the mouse cursor:
    HideCursor;
    
    % Returns as default the mean gray value of screen:
    gray=GrayIndex(screenNumber); 

    % Open a double buffered fullscreen window on the stimulation screen
    % 'screenNumber' and choose/draw a gray background. 'w' is the handle
    % used to direct all drawing commands to that window - the "Name" of
    % the window. 'wRect' is a rectangle defining the size of the window.
    % See "help PsychRects" for help on such rectangles and useful helper
    % functions:
    [w, wRect]=Screen('OpenWindow',screenNumber, gray);
    

    % Set priority for script execution to realtime priority:
    priorityLevel=MaxPriority(w);
    Priority(priorityLevel);
    
        
    % Wait for mouse click:
    GetClicks(w);
                
    % Clear screen to background color (our 'gray' as set at the
    % beginning):
    Screen('Flip', w);
        
    % Wait a second before starting trial
    WaitSecs(1.0);                    
             
        
    % make texture image out of image matrix 'imdata'
    tex=Screen('MakeTexture', w, imdata);
            
    % Draw texture image to backbuffer. It will be automatically
    % centered in the middle of the display if you don't specify a
    % different destination:
    Screen('DrawTexture', w, tex);
            
    % Screen('DrawDots', windowPtr, xy [,size] [,color] [,center] [,dot_type]);
    Screen('DrawDots', w, [720 450], 10, [255 0 0], [0 0], 1)      
    
    
    % Show stimulus on screen at next possible display refresh cycle,
    % and record stimulus onset time in 'startrt':
    [VBLTimestamp startrt]=Screen('Flip', w);
            
    % Wait 10 s 
    WaitSecs(10);
   
    % Clear screen to background color 
    Screen('Flip', w);
          
   
    % Cleanup - close window, show mouse cursor, 
    % switch Matlab/Octave back to priority 0 -- normal
    % priority:
    Screen('CloseAll');
    ShowCursor;
    fclose('all');
    Priority(0);
    
    % End of main prg:
    return;
catch
    % catch error: This is executed in case something goes wrong in the
    % 'try' part due to programming error etc.:
    
    % Do same cleanup as at the end of a regular session...
    Screen('CloseAll');
    ShowCursor;
    fclose('all');
    Priority(0);
    
    % Output the error message that describes the error:
    psychrethrow(psychlasterror);
end % try ... catch ... end %