我认为您需要做的就是在图像中包含alpha通道
MakeTexture
.
% slightly modified boilerplate -- non-fullscreen by default,
% and set the background color (no need for all the FillRects)
PsychDefaultSetup(2);
Screen('Preference', 'SkipSyncTests', 1);
screenNum = max(Screen('Screens')); % set screen
Screen('Preference', 'VisualDebugLevel', 3);
[w, rect] = Screen('OpenWindow', screenNum, [100 100 100], [0 0 400 400]);
Screen('BlendFunction', w, 'GL_SRC_ALPHA', 'GL_ONE_MINUS_SRC_ALPHA');
% image presentation rectangles
smImSq = [0 0 250 250];
[smallIm, xOffsetsigS, yOffsetsigS] = CenterRect(smImSq, rect);
这是一张透明背景的图像(为了再现性)。
% from http://pngimg.com/upload/cat_PNG100.png
[img, ~, alpha] = imread('cat.png');
size(img)
%% 2557 x 1993 x 3 (rgb)
我们将制作一个不带alpha通道的纹理,一个带。
texture1 = Screen('MakeTexture', w, img);
img(:, :, 4) = alpha;
texture2 = Screen('MakeTexture', w, img);
首先,没有alpha通道的图像。
Screen('DrawTexture', w, texture1, [], smallIm);
Screen('Flip', w);
然后是RGBA纹理。
Screen('DrawTexture', w, texture2, [], smallIm);
Screen('Flip', w);
sca;