====== MGL ======
{{mgl:mgllogo.png?150x150}}
Mgl is a suite of mex/m files for displaying visual psychophysics stimuli and writing experimental programs in Matlab.
Runs on Mac OS X and is compatible with latest versions of the Mac OS (Ventura as of this writing 8/11/2023). It is based on [[https://developer.apple.com/documentation/metal|Metal]], Apple's low-level graphics card libarary. See [[:mgl:pubs|here]] for a list of publications that have used mgl and how to cite use of mgl in your manuscript!
====== A quick overview ======
mgl is a set of matlab functions for displaying full screen visual stimuli from matlab. It is based on Apple Metal with simple functions that can be used to code various kinds of visual stimuli. It can be used on Mac OS X systems only.
* mgl contains a set of higher-level [[mgl:taskReference|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.
* mgl is integrated with [[:mrTools:Overview|mrTools]] so that you can easily extract trial timing to do analyses such as deconvolution on fMRI data collected with experiments written in mgl (see [[:mrTools:analyses#event_related_analysis|here]]).
* Stimuli can be displayed full screen or in a window (helpful for debugging on a system that only has one display).
* With a [[:mgl:functionReferenceCoordinateFrames#mglvisualanglecoordinatesvisual_angle_coordinates|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.
* It can interface with the [[http://www.sr-research.com/EL_1000.html|Eyelink]] eye tracker (see [[:mgl:functionreferenceeyelink#overview|here]]).
* You can read and write digital signals with [[http://sine.ni.com/nips/cds/view/p/lang/en/nid/201630|National Instruments]] digital I/O boards (see [[:mgl:functionReferenceDigIO|here]]).
* You can set the [[:mgl:functionReferenceGammaTable|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 [[:mgl:taskReferenceHowTos#how_to_calibrate_the_monitor|here]]).
* You can display [[:mgl:functionReferenceImages|images]], draw [[:mgl:functionReferenceText|text]], draw [[:mgl:functionReferenceDrawing|lines, dots, quads and other simple shapes]].
* You can get accurate [[:mgl:functionReferenceKeyboardAndMouse|keyboard and mouse]] event information.
* You can play [[:mgl:functionReferenceSound|sounds]].
* You can [[:mgl:functionReferenceScreen#mglswitchdisplayswitch_between_multiple_monitors|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.6-10.8) and with the latest versions of Matlab (7.4-8.1) as of 6/19/2013. 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 [[:mgl:knownissues|here]]. If you are using an older version of Mac OS or Matlab and are having trouble getting MGL to run, you may need to [[:mgl:knownissues#recompiling_MGL|recompile]].
* Javascript code (jgl) for doing psychophysics experiments on Mechanical Turk
The best way to see whether it will be useful to you is to try out the [[:mgl:functionReferenceDemoPrograms|mglTest]] programs and also the sample experiment [[:mgl:taskReferenceOverview#testExperiment|testExperiment]]. A basic "hello world" program can be written in four lines:
% 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:
mglClose;