-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdraw_Bg_Ct_texture.m
119 lines (106 loc) · 4.51 KB
/
draw_Bg_Ct_texture.m
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
function draw_Bg_Ct_texture(ex, Bg_tex, Ct_tex, Bg_masktex, D_Bg, D_Ct, Bg_shift, Ct_shift, angleBG)
%
% All units should be as pixels.
% Bg_tex and Ct_tex are texture indexes created by 'MakeTexture' in Screen.
% Shift parameters can be either [x] or [x y].
%
% inputs:
% s (screen object) should contain those fields: [s.window, s.screenRect]
% ex.disp.winptr, ex.disp.winrect
% Annulus (Ct/Bg) is now commented.
%
% Oct 2016 Juyoung Kim
%
%% struct 's' has s.window and s.screenRect field?
s.window = ex.disp.winptr;
s.screenRect = ex.disp.winrect;
%%
angleCenter = 0;
if nargin < 9
angleBG = 0;
end;
if nargin < 8
Ct_shift = [];
end;
if nargin < 7
Bg_shift = [];
end;
%%
Bg_shift = round(Bg_shift);
Ct_shift = round(Ct_shift);
%%
switch length(Bg_shift)
case 0
Bg_xshift = 0;
Bg_yshift = 0;
case 1
Bg_xshift = Bg_shift;
Bg_yshift = 0;
case 2
Bg_xshift = Bg_shift(1);
Bg_yshift = Bg_shift(2);
otherwise
error('Bg_shift is not properly defined.');
end
switch length(Ct_shift)
case 0
Ct_xshift = 0;
Ct_yshift = 0;
case 1
Ct_xshift = Ct_shift;
Ct_yshift = 0;
case 2
Ct_xshift = Ct_shift(1);
Ct_yshift = Ct_shift(2);
otherwise
error('Ct_shift is not properly defined.');
end
%% Dst Rects: Final rectangles on the screen
dstRect_Bg = CenterRect([0 0 D_Bg D_Bg], s.screenRect);
dstRect_Ct = CenterRect([0 0 D_Ct D_Ct], s.screenRect);
%% Source Rects = Size of Dst Rects, but with offset: Define the subpart of the texture
% only effective when the shift parameters are given.
% Original texture object should be larger than the size of scrRect
% due to random the shift.
srcRect_Bg = [Bg_xshift Bg_yshift D_Bg+Bg_xshift D_Bg+Bg_yshift];
srcRect_Ct = [Ct_xshift Ct_yshift D_Ct+Ct_xshift D_Ct+Ct_yshift];
%% Draw BG grating texture
if isempty(Bg_shift)
Screen('DrawTexture', s.window, Bg_tex, [], dstRect_Bg, angleBG);
else
Screen('DrawTexture', s.window, Bg_tex, srcRect_Bg, dstRect_Bg, angleBG);
end
%%
% Draw BG Mask (or aperture)
Screen('Blendfunction', s.window, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); % Juyoung add
Screen('DrawTexture', s.window, Bg_masktex, [0 0 D_Bg D_Bg], dstRect_Bg, angleBG);
% annulus
%Screen('FillOval', s.window, annu_Color, rectAnnul);
%%
% Disable alpha-blending, restrict following drawing to alpha channel:
Screen('Blendfunction', s.window, GL_ONE, GL_ZERO, [0 0 0 1]);
% Clear 'dstRect' region of framebuffers alpha channel to zero:
%Screen('FillRect', s.window, [0 0 0 0], dstRect_Ct);
Screen('FillRect', s.window, [0 0 0 0], dstRect_Bg);
% Fill circular 'dstRect' region with an alpha value of 255:
Screen('FillOval', s.window, [0 0 0 255], dstRect_Ct);
% Enable DeSTination alpha blending and reenable drawing to all
% color channels. Following drawing commands will only draw there
% the alpha value in the framebuffer is greater than zero, ie., in
% our case, inside the circular 'dst2Rect' aperture where alpha has
% been set to 255 by our 'FillOval' command:
% Screen('Blendfunction', windowindex, [souce or new], [dest or
% old], [colorMaskNew])
Screen('Blendfunction', s.window, GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA, [1 1 1 1]);
%%
% Draw 2nd (Center) texture, but only inside alpha == 255 circular
% aperture, and at an angle of 90 degrees: Now the angle is 0
% if isempty(Ct_shift)
% Screen('DrawTexture', s.window, Ct_tex, [], dstRect_Ct, angleCenter);
% else
% Screen('DrawTexture', s.window, Ct_tex, srcRect_Ct, dstRect_Ct, angleCenter);
% end
Screen('DrawTexture', s.window, Ct_tex, srcRect_Ct, dstRect_Ct, angleCenter);
% Restore alpha blending mode for next draw iteration:
Screen('Blendfunction', s.window, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
end