我的实验存在时间问题,我正在尝试用闪存盒实现SSVEP拼写器。在每个帧我实现以下代码,创建具有指定颜色的矩形,我使用“DrawText”来指示字母的文本。然而,当我这样做时,错过的翻转数量非常高(超过90%),当我删除所有文本绘图时,性能正常且非常好(约1%)。
我使用的是64位窗口,使用Matlab 2017b,Psychtoolbox-3,我安装了Gstreamer。
我的问题是如何在没有性能问题的情况下正确显示文本?我尝试了DrawText和DrawFormattedText,但没有变化。我试图将字母保存到纹理中并加载纹理,但我不确定如何显示文本并在其上方绘制框,并显示它们。
非常感谢。
function all_rects = create_rects(char_struct,window,drawing_colors,drawing_color_index,black,cue,text_texture)
penWidthPixels = 2;
Screen('TextFont', window, 'Courier New');
Screen('TextSize', window, 15);
num_targets = length(char_struct);
all_rects = nan(4,num_targets);
for i=1:num_targets
baseRect = [0 0 char_struct(i).size(1) char_struct(i).size(2)];
all_rects(:,i) = CenterRectOnPointd(baseRect, char_struct(i).x_location, char_struct(i).y_location);
Screen('FillRect',window,reshape(drawing_colors(drawing_color_index(i)+1,:),[1,3]),all_rects(:,i));
if length(char_struct(i).text) > 1 && ~strcmp(char_struct(i).text,'SPACE')
Screen('DrawText',window, char_struct(i).text,char_struct(i).x_location-15, char_struct(i).y_location+3,0, 100)
elseif strcmp(char_struct(i).text,'SPACE')
Screen('DrawText',window,char_struct(i).text,char_struct(i).x_location-40,char_struct(i).y_location+3,0,100);
else
Screen('DrawText',window, char_struct(i).text,char_struct(i).x_location-5, char_struct(i).y_location+3,0, 100);
end
end
Screen('FrameRect', window, black, all_rects,penWidthPixels);
if cue ~=0
Screen('FrameRect', window, [255 0 0], all_rects(:,cue),penWidthPixels);
end
Screen('DrawingFinished', window);
翻转在主循环中实现:
vbl = Screen('Flip', window,vbl + 0.5 * ifi);
答案 0 :(得分:0)
如您所述,预先计算文本(文本本身或整个窗口)作为纹理将在演示循环期间节省资源。您可以使用与其他Psychtoolbox绘图功能相同的方式在纹理上绘制框,只需在翻转屏幕之前叠加两个框:
Screen('DrawTexture', window, text_texture);
Screen('FrameRect', window, black, all_rects, penWidthPixels);
Screen('Flip', window);