Gardner Lab

Psychology Department

Neurosciences Institute

Stanford University


日本語   

Drawing text

mglTextSet: Set parameters for drawing text

purpose: Set text properties for mglText
usage: mglTextSet(fontName,<fontSize>,<fontColor>,<fontVFlip>,<fontHFlip>,<fontRotation>,<fontBold>,<fontItalic>,<fontUnderline>,<fontStrikeThrough>)

argument value
fontName 'fontName' (defaults to 'Times Roman')
fontSize font point size (defaults to 36)
fontColor [r g b] where r, g and b are values between 0 and 1 (defaults to [1 1 1])
fontVFlip 0 = no vertical flip, 1 = vertical flip (defaults to 0)
fontHFlip 0 = no horizontal flip, 1 = horizontal flip (defaults to 0)
fontRotation rotation in degrees (defaults to 0)
fontBold 0 for normal, 1 for bold (defaults to 0)
fontItalic 0 for normal, 1 for italic (defaults to 0)
fontUnderline 0 for normal, 1 for underline (defaults to 0)
fontStrikethrough 0 for normal, 1 for strikethrough (defaults to 0)
mglOpen;
mglVisualAngleCoordinates(57,[16 12]);
mglTextSet('Helvetica',32,[0 0.5 1 1],0,0,0,0,0,0,0);
mglTextDraw('Hello There',[0 0]);
mglFlush;

mglText: Create a texture from a string

purpose: Creates a texture from a string.
usage: tex = mglText('string')

argument value
string The string you want to draw
mglOpen;
mglVisualAngleCoordinates(57,[16 12]);
mglTextSet('Helvetica',32,[0 0.5 1 1],0,0,0,0,0,0,0);
thisText = mglText('hello')
mglBltTexture(thisText,[0 0],'left','top');
mglFlush;

Normally you will only set one output argument which is a texture usable by mglBltTexture. But if you have two output arguments

[tex texMatrix] = mglText('hello');

texMatrix will contain a 2D matlab array that has a rendering of the text (i.e. it will have values from 0-255 that represent the string). You can modify this matrix as you want and then use mglCreateTexture to create it into a texture that can be displayed by mglBltTexture

mglTextDraw: Draws text to screen (simple but slow)

purpose: wrapper around mglText and mglBltTexture to draw some text on the screen. If you need to draw text more quickly, you will have to pre-make the text textures with mglText and then use mglBltTexture when you want it. Otherwise, for non time-critical things this functions should be used.
usage: mglTextDraw(str,pos,<hAlignment>,<vAlignment>)

argument value
str desired string
pos [x y] position on screen
hAlignment -1 = left, 0 = center, 1 = right (defaults to center)
vAlignment -1 = top, 0 = center, 1 = bottom (defaults to center)
mglOpen;
mglVisualAngleCoordinates(57,[16 12]);
mglTextSet('Helvetica',32,[0 0.5 1 1],0,0,0,0,0,0,0);
mglTextDraw('Hello There',[0 0]);
mglFlush;

mglStrokeText: Fast no-frills line-based text drawing (does not use texture memory)

purpose: Draws a stroked fixed-width character or string on MGL display. Default width is 1, default height 1.8 (in current screen coordinates)
usage: [x,y]=mglStrokeText( string, x, y, scalex, scaley, linewidth, color, rotation );

argument value
string text string. Unsupported characters are printed as #
x,y center coordinates of first character (current screen coordinates)
scalex scale factor in x dimension (relative to character) (current screen coordinates). Note that text can be mirrored by setting this factor to a negative value.
scaley scale factor in y dimension (relative to character) (current screen coordinates). Optional, defaults to scalex.
linewidth width of line used to draw text. Default 1.
color text color. Default [1 1 1]
rotation in radians. Default 0.
OUTPUT x,y position after last letter (for subsequent calls) [optional]
mglOpen;
mglVisualAngleCoordinates(57,[16 12]);
mglStrokeText('Hello',0,0);
mglFlush;