-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopenPTB.m
More file actions
78 lines (59 loc) · 2.38 KB
/
openPTB.m
File metadata and controls
78 lines (59 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
function [ PTB ] = openPTB( bgclr, varargin )
%UNTITLED8 Summary of this function goes here
% Detailed explanation goes here
fprintf('\n\n');
fprintf('Opening PTB window...\n')
smallscreen = 0;
if nargin > 1
if strcmp(varargin{1}, 'smallscreen')
smallscreen = 1;
elseif strcmp(varargin{1}, 'smallscreenhome')
smallscreen = 2;
end
end
% PTB parameters
screens = Screen('Screens');
screenNumber = max(screens);
% Here we call some default settings for setting up Psychtoolbox
PsychDefaultSetup(2);
% init PTB structure
PTB = {};
% Open the window
if smallscreen == 1
[PTB.window, PTB.windowRect] = PsychImaging('OpenWindow', screenNumber, bgclr, [0 0 1267 800]);
elseif smallscreen == 2
[PTB.window, PTB.windowRect] = PsychImaging('OpenWindow', screenNumber, bgclr, [0 0 850 530]);
else
[PTB.window, PTB.windowRect] = PsychImaging('OpenWindow', screenNumber, bgclr);
end
% clear the screen
Screen('Flip', PTB.window);
% makes it so that characters typed don't show up in the command window
ListenChar(-1);
% hide cursor
HideCursor(PTB.window);
% Set up alpha-blending for smooth (anti-aliased) lines to draw fixation cross
Screen('BlendFunction', PTB.window, 'GL_SRC_ALPHA', 'GL_ONE_MINUS_SRC_ALPHA');
% Return width and height of the graphics window/screen in pixels
[PTB.width, PTB.height] = Screen('WindowSize', PTB.window);
% Retrieve monitor refresh rate
PTB.hz = Screen('NominalFrameRate', PTB.window);
% Get the centre coordinate of the window in pixels.
[PTB.xCenter, PTB.yCenter] = RectCenter(PTB.windowRect);
% Query the inter-frame-interval. This refers to the minimum possible time
% between drawing to the screen
PTB.ifi = Screen('GetFlipInterval', PTB.window);
% Get the maximum coded luminance level (this should be 1)
PTB.maxLum = Screen('ColorRange', PTB.window);
% Print resolution and refreh rate in Matlab's Command Window
fprintf('\n\n\n\n');
fprintf('Running on a %d x %d screen at %d Hz\n', PTB.width, PTB.height, PTB.hz);
fprintf('Inter-frame-interval is %d\n', PTB.ifi);
fprintf('Maximum coded luminance is %d\n', PTB.maxLum);
fprintf('\n\n\n\n');
% Init UI
Screen('Preference', 'DefaultFontSize', 20);
Screen('TextFont', PTB.window, 'Consolas');
% KB
KbName( 'UnifyKeyNames' );
end