Displaying Graphics with the PsychToolbox

Displaying images (or other graphical context) with the PsychToolbox usually involves the handling of "invisible" screens. When showing stimuli to the subjects you want to do it as quickly and as accurately as possible. The major limition will be the refresh rate of your monitor, but some care must be taken not to introduce further software delays. The easiest solution is to create or load all your stimuli or instruction screen into the graphic card (or in a special format in the main memory) before you start the actual experiment. When you want to display your stimulus in the experiment you then just have to copy the appropriate (hidden) screen to the (visible) main screen. With modern computers that have a fast data transfer (bus) systems this will be accomplished within nanoseconds.

Opening Screens

The main function in the PsychToolbox is the SCREEN function. SCREEN('OPENWINDOW', 0) will return a handle to the current (visible) screen. This handle can be used in subsequent drawing calls. You can create multiple hidden screen by passing the handle to the SCREEN('OPENOFFSCREEN') function. A prototypic source code would like like this

% Open a window in center of screen

screenNumber=0;

rect=CenterRect?([0 0 200 200],Screen(screenNumber,'Rect'));

window=Screen(screenNumber,'OpenWindow?',[],rect);

w(i)=Screen(window,'OpenOffscreenWindow?');

% [...] Draw your stuff

HideCursor?;

rect=Screen(w,'Rect');

% Wait for blanking, then display offscreen

Screen(window,'WaitBlanking?');

Screen('CopyWindow?',w,window,rect,rect);

% Wait for key press

KbWait?;

ShowCursor?;

% Close the on- and off-screen windows

Screen('CloseAll?');


Last edited on Friday, June 6, 2003 7:14:01 am.

Valid XHTML 1.0! Valid CSS!
Page Execution took 6.137 seconds