Mgl is a suite of mex/m files for displaying visual psychophysics stimuli and writing experimental programs in Matlab. Runs on Mac OS X (G4/5 and Intel 32 and Intel 64 bit OS Versions 10.5-10.7) Version 2.0. An older version 1.5 runs on Linux.
mgl is a set of matlab functions for displaying full screen visual stimuli from matlab. It is based on OpenGL functions, but abstracts these into more simple functions that can be used to code various kinds of visual stimuli. It can be used on Mac OS X systems (a Windows beta is in the works and an older but fully usable version (1.5) exists for Linux).
- mgl contains a set of higher-level routines for helping you write stimulus programs which takes care of parameter randomization, timing of trials, synching with MRI scanners, collection of eye data etc.
- Stimuli can be displayed full screen or in a window (helpful for debugging on a system that only has one display).
- With a single command that specifies the distance to and size of a monitor, the coordinate system can be specified in degrees of visual angle, thus obviating the need to explicitly convert from the natural coordinate frame of psychophysics experiments into pixels.
- You can set the gamma table for example to linearize the output of your monitor.
- You can calibrate monitors automatically through serial connection to a PhotoResearch PR650, Minolta or Topcon photometer (see here).
- You can get accurate keyboard and mouse event information.
- You can play sounds.
- You can play quicktime movies.
- You can control multiple screens for example to control stereo displays.
- mgl is 64-bit compliant.
- mgl works with the latest versions of Mac OS X (10.5-10.8) and with the latest versions of Matlab (7.4-7.12) as of 10/21/2011. In general, we stay reasonably up to date with releases of Mac OS and Matlab. If we encounter any compatibility issues, that information will generally be posted here.
% Open the screen, 0 specifies to draw in a window. % 1 would be full screen in the main display % 2 would be full screen in a secondary display, etc... >> mglOpen(0); % Select the coordinate frame for drawing % (e.g. for a monitor 57 cm away, which has width and height of 16 and 12 cm). >> mglVisualAngleCoordinates(57,[16 12]); % Draw the text in the center (i.e. at 0,0) >> mglTextDraw('Hello World!',[0 0]); % The above is drawn on the back-buffer of the double-buffered display % To make it show up you flush the display. % This function will wait till the end of the screen refresh >> mglFlush;
When finished, with displaying the stimuli, you simply close the screen:
A couple of things that distinguish MGL from other packages for doing psychophysics experiments using Matlab.
1) Simple standalone functions. We were aiming to make the code as simple as possible, so that we and others could extend functionality as easily as possible. So a major design goal was to keep each function as atomic and simple as possible - every function is one C/MEX file that has OS specific code clearly separated out, typically as a separate function. Something like the philosophy behind UNIX where kitchen sink type functions are frowned upon. This was so that it would be easy to hack in the future and for others. New functionality typically gets added as a separate function so we don't risk breaking existing code. Functions are simple so that they are easier to maintain against OS upgrades (the back end of MGL was rewritten a few years ago using objective-C so that we could be 64-bit compliant).
2) Task library. We have a low-level library for displaying stimuli and accessing hardware as well as a task library which sits on top of that. The task library simplifies writing experiments since it takes care of timing, trials, synching with digital pulses, interfacing with eye-trackers etc. Each new experiment simply implements callback functions that handle how to draw the screen, what to do when a subject responds etc. This makes it quick to write new experiments and makes sure that problems fixed for one experiment are solved for all experiments.