我的实验有时间问题,我正在尝试实现一个带有闪光框的SSVEP拼写器。在每一帧中,我实现以下代码来创建具有指定颜色的矩形,并使用"DrawText“来表示字母文本。然而,当我这样做时,错失翻转的数量非常高(超过90%),当我删除所有的文本绘制时,性能是正常的,并且非常好(大约1%)。
我使用的是Windows7 64位,使用Matlab 2017b,Matlab-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);发布于 2018-05-22 23:28:13
正如您所提到的,将文本(文本本身或整个窗口)预先计算为纹理将在演示循环期间节省资源。您可以使用与其他manner绘制函数相同的方式在纹理顶部绘制长方体,只需在翻转屏幕之前将两者叠加即可:
Screen('DrawTexture', window, text_texture);
Screen('FrameRect', window, black, all_rects, penWidthPixels);
Screen('Flip', window);https://stackoverflow.com/questions/50450921
复制相似问题