Persistent clipping with drawformattedtext

Similar to the authors of these posts in the MATLAB Answers forum, as well as people posting on Stack Overflow (e.g., matlab - Psychtoolbox - Text for Instruction - Stack Overflow), I can’t get rid of the clipping when I use drawformattedtext. Basically, whether it is one or multiple lines, the text always has its top 1/3 or so missing.

I added extra line spacing, I tried various standard fonts, I adjusted my display resolution and scaling, and found that the described ptb_drawformattedtext_disableClipping solution did not seem to have any effect. Nor did requesting the optional 3rd return parameter ‘textbounds’.

Screen(‘DrawText’) does not clip text.

I am using Windows 10 on a Dell laptop, MATLAB version 2020b, the most recent version of PTB.

Please provide complete and minimal example code. Also, verify that the high quality text plugin is working, if it falls back to the gdi renderer, all bets are off

Thank you @dcnieho, I get this problem even just running this demo:

Here’s what it looks like:

type = Screen(‘Preference’,‘TextRenderer’)

Returns 0, so I’ll have a look around for some kind of outdated libfreetype.dll file as per the docs.

Edit: I found libfreetype.dll and renaming and/or removing didn’t fix it. I have re-installed gstreamer twice, rebooting each time.

Ah, from your reply i assume you have read help DrawTextPlugin. Hope you can solve the problem. Also make sure you installed exactly the right GStreamer version, not the newest. help GStreamer for a direct download link.

GStreamer 1.18 is currently the sweet spot for functionality on MS-Windows. 1.18.5 is tested, 1.18.6 is out and likely works also, as a bug fix release on top of 1.18.5.

GStreamer 1.20 for Windows currently breaks the high quality text renderer under Matlab due to shipping an incompatible fontconfig-1.dll and some other bugs. Under Octave 6.4 it would work, as that brings its own compatible libfontconfig-1.dll.

macOS and Linux don’t suffer these problems atm.

Thank you to both. I uninstalled the current version of GStreamer (1.20) and used the direct link provided by PTB to reinstall. The simple formatted text demo now displays the text correctly.

The best way to thank us and to help keep PTB alive is to buy a support membership. If your lab takes part in our user survey, you’d even get it with a small discount.

1 Like

Hi There,

I am unfortunately having the same issues. I am currently using Windows 10 version 10.019044 on MatlabR2018b, Psychtoolbox 3.0.18 - Flavor: beta, and GStreamer 1.20. I tried uninstalling GStreamer and putting in the 1.18.5 through the Psychtoolbox website but that link didn’t work. So instead I looked it up on Google. See link attached.

I tried using the 1st link, 4th link and the 3rd last link (wasn’t sure which one was correct) on their own but none of them worked. When I put these Gstreamer programs in drawtext would not even render anymore and psychtoolbox would crash.

Basically getting the same issue as from here

I deleted the cache as instructed in the discussion above, but it has never appeared back.

Could you please advise me on what further steps I should take?

Best Regards,

The provided link from help GStreamer and our web page works fine, as posted here. I just tried it:


Hi Mario,

Thanks so much for sending! Yep the link is now working for me on the website too, weird that it was giving me a 404 error yesterday. I downloaded using the link provided but Psychtoolbox is still crashing when rendering the text. I tested it using the basic demo with text online, but it still won’t run.

I have the printout below!

PTB-INFO: This is Psychtoolbox-3 for Microsoft Windows, under Matlab 64-Bit (Version 3.0.18 - Build date: Jun 27 2022).
PTB-INFO: OS support status: Windows 10 (Version 10.0) supported and tested to some limited degree.
PTB-INFO: Type ‘PsychtoolboxVersion’ for more detailed version information.
PTB-INFO: Most parts of the Psychtoolbox distribution are licensed to you under terms of the MIT License, with
PTB-INFO: some restrictions. See file ‘License.txt’ in the Psychtoolbox root folder for the exact licensing conditions.

PTB-INFO: For information about paid support, support memberships and other commercial services, please type
PTB-INFO: ‘PsychPaidSupportAndServices’.

PTB-INFO: The detected endline of the vertical blank interval is equal or lower than the startline. This indicates
PTB-INFO: that i couldn’t detect the duration of the vertical blank interval and won’t be able to correct timestamps
PTB-INFO: for it. This will introduce a very small and constant offset (typically << 1 msec). Read ‘help BeampositionQueries’
PTB-INFO: for how to correct this, should you really require that last few microseconds of precision.
PTB-INFO: Btw. this can also mean that your systems beamposition queries are slightly broken. It may help timing precision to
PTB-INFO: enable the beamposition workaround, as explained in ‘help ConserveVRAMSettings’, section ‘kPsychUseBeampositionQueryWorkaround’.

PTB-INFO: OpenGL-Renderer is ATI Technologies Inc. :: Radeon 540X Series :: 4.6.14800 Compatibility Profile Context 30.0.15020.1001
PTB-INFO: VBL startline = 1080 , VBL Endline = 1080
PTB-INFO: Measured monitor refresh interval from beamposition = 16.661051 ms [60.020223 Hz].
PTB-INFO: Will use beamposition query for accurate Flip time stamping.
PTB-INFO: Measured monitor refresh interval from VBLsync = 16.656810 ms [60.035505 Hz]. (50 valid samples taken, stddev=0.511993 ms.)
PTB-INFO: Reported monitor refresh interval from operating system = 16.666667 ms [60.000000 Hz].
PTB-INFO: Small deviations between reported values are normal and no reason to worry.
PTB-INFO: ==============================================================================================================================
PTB-INFO: WINDOWS DWM DESKTOP COMPOSITOR IS ACTIVE. On this Windows-10 or later system, Psychtoolbox can no longer reliably detect if
PTB-INFO: this will cause trouble for timing and integrity of visual stimuli or not. You might be just fine, or you could be in trouble.
PTB-INFO: Use external measurement equipment and independent procedures to verify reliability of timing if you care about proper timing.
PTB-INFO: ==============================================================================================================================

WARNING: Couldn’t compute a reliable estimate of monitor refresh interval! Trouble with VBL syncing?!?


One or more internal checks (see Warnings above) indicate that synchronization
of Psychtoolbox to the vertical retrace (VBL) is not working on your setup.

This will seriously impair proper stimulus presentation and stimulus presentation timing!
Please read ‘help SyncTrouble’ for information about how to solve or work-around the problem.
You can force Psychtoolbox to continue, despite the severe problems, by adding the command
Screen(‘Preference’, ‘SkipSyncTests’, 1); at the top of your script, if you really know what you are doing.

PTB-ERROR: Text rendering failed. The most likely cause for this is that no suitable text font could be found
PTB-ERROR: by libfontconfig. This is often the case when the fontconfig cache gets somehow corrupted, especially
PTB-ERROR: on Windows or macOS. Deleting that cache manually and restarting the application may help.
PTB-ERROR: See ‘help DrawTextPlugin’ for other causes of trouble and for troubleshooting instructions.
Error in function TextBounds: Usage error
The external text renderer plugin failed to render the text string for some reason!

WARNING: This session of your experiment was run by you with the setting Screen(‘Preference’, ‘SkipSyncTests’, 1).
WARNING: This means that some internal self-tests and calibrations were skipped. Your stimulus presentation timing
WARNING: may have been wrong. This is fine for development and debugging of your experiment, but for running the real
WARNING: study, please make sure to set Screen(‘Preference’, ‘SkipSyncTests’, 0) for maximum accuracy and reliability.
Error using Screen

[normBoundsRect, offsetBoundsRect, textHeight, xAdvance] = Screen(‘TextBounds’, windowPtr, text [,x] [,y] [,yPositionIsBaseline] [,swapTextDirection]);

Error in DrawFormattedText (line 295)
theight = RectHeight(Screen(‘TextBounds’, win, tstring));

Error in DemoscriptText (line 35)
DrawFormattedText(window, ‘Hello World’, ‘center’,…

Please let me know if you have any advice on how to resolve the situation.

Best Regards,

This is not a crash, but an error. That’s the error message you get when fonts can’t be found because something’s wrong with the fontconfig cache. Try the measures in help DrawTextPlugin to fix it. Otherwise help PsychPaidSupportAndServices tells you how to get 30 minutes of my paid advice as a start.


Hi Mario,

Thanks for your quick reply! I checked out the help DrawTextPlugin printout for solutions but nothing really seemed to work. My guess is that the cache file is being stored somewhere other than the fontconfig folder, but I’m not really sure how to track it down. I am a support member and would definitely take up your offer for 30 minutes of help. I also sent an message on so you can verify. Can I contact you to plan a time to talk sometime next week?

Best Regards,

Hi, no e-mail arrived at our business mailbox, but the way verification works is that I’d need an authentication token generated from your support license key, generated via the PsychPaidSupportAndServices function. You can simply post it here, we don’t generally do face-to-face communication at specific times, support is generally via this forum, or GitHub issues, so everybody can benefit or participate.

The first bit of info I’d then need to know is the content of the file

The instructions are at the top of the output of PsychPaidSupportAndServices, given you bought the membership already, you’d just have to answer ‘y’ when it asks if you need support and have a license key, then enter the OrderId and license key you received, and it would generate the token for you. We do have this method with tokens instead of posting screenshots of your purchase, so no personally identifying information like name, address, e-mail address etc. is leaked, and also nobody can easily steal and abuse your license. It is really not advisable to post this kind of info publicly, as you just did, but as you posted this on a public forum, thank god at least we are not liable for any abuse or EU general data protection regulation violations wrt. your information.

Anyway, from the screenshot - which luckily for you doesn’t show your secret license key - I guess you did buy a membership so lets proceed.

Hmm, file looks fine and has correct content. I was hoping for some messed up file from your previous installation attempts of wrong GStreamer versions.

Can you show me what is stored in the C:\Users\vignash\.cache\ directory, assuming here that vignash would be your user name? Also C:\Users\vignash\AppData\Local\fontconfig\cache\ folder? E.g., a screenshot of file explorer, showing the file names and modification dates and file sizes? Some of these files or directories may not exist. Also in Matlab the output of getenv('HOME') and getenv('USERPROFILE') and getenv('XDG_CACHE_HOME').

[Time used so far: 15 minutes out of 30 minutes available]

Hi Mario,

Thanks for letting me know. I have deleted my prior post to get rid of the screenshot.

Below I have attached a screen shot of C:\Users\vignash.cache\fontconfig and

CUsersvignash.cachefontconfig directory

As suggested in the past forum post I listed earlier, I had deleted the files in C:\Users\vignash\AppData\Local\fontconfig\cache\ to solve the issue, but that didn’t seem to work. No new cache files were formed since I deleted those files and ran Psychtoolbox. I have restored the previous deleted files so that you can see what they looked like.

Below you will also see the printouts for getenv(‘HOME’) and getenv(‘USERPROFILE’) and getenv(‘XDG_CACHE_HOME’).


ans =

0×0 empty char array


ans =



ans =

0×0 empty char array

Best Regards,

Ok. Restoring the files was not quite what i asked for, but:

  1. Delete the whole fontconfig folder in both locations C:\Users\vignash\AppData\Local\ and C:\Users\vignash.cache\

  2. Quite and restart Matlab.

  3. Try DrawSomeTextDemo demo again. The hope is you didn’t delete all files in both locations, and fontconfig was choking on some stale old outdated file, possibly invalid/useless due to the wrong installed GStreamer packages before.

  4. If it works without errors, great, let me know. If not, post better quality screenshots of those two folders again.

[Time spent: 41 Minutes of 30 minutes paid for → 11 Minutes overtime!]

Hi Mario,

So it basically works!

I deleted both files as recommended. And then ran the basic demo script with text from the Psychtoolbox tutorial website.

When running in full screen mode, since my laptop was connected to a second computer monitor that extends my screen from my laptop, the Psychtoolbox Screen was only showing the left half of my Psychtoolbox screen on my laptop screen, cutting off the second half. This second half of the Psychtoolbox screen wasn’t present at all, not even on the second monitor. Not sure why this happened… I unplugged my second monitor, and then ran “clear all” in the command window. I then ran the code, and the text rendered properly, full screen on my laptop’s single monitor.

I then ran another line of code, to test a Psychtoolbox screen window smaller than full screen size using the following line of code, while having my second monitor plugged in.

[w, rect] = Screen(‘OpenWindow’,screenNum, , [0 0 1200 800]);

This Psychtoolbox screen opened on my laptop screen, without any text rendering issues.

Thanks for all your help! I really appreciate it!

I guess I am good for now, but if you have some time to comment on why the Psychtoolbox screen in full screen mode shows only half of the screen when another monitor is plugged in, that would be appreciated.

Best Regards,

Good, problem solved! So it was basically user error, by not exactly following the troubleshooting instructions in help DrawTextPlugin. Case closed :slight_smile:

Your paid membership is completely used up with this, in fact you got over 15 minutes of extra free work time.

MS-Windows is known to be very fragile and often buggy when it comes to multi-display configurations, especially wrt. visual presentation timing if that matters to you. Displaying something on screen 1 or 2 should only display on that screen, but displaying on screen 0 should display a window covering both screen 1 and 2, useful for dual-display stereoscopic / binocular stimuli, as the PTB-INFO output explains on Windows. I could imagine that if your monitors are not of the same resolution, or of different pixel density or with different scaling factors, or there is one of many display driver bugs, things will go sideways. Specifying screenId 1 or 2 in PsychImaging('Openwindow', screenId, ...) might have worked better. Intel graphics chips are especially bad on Windows.

→ The simple advice is always to switch to Linux, with recommended graphics cards (ie. not NVidia) where life with multi-display, HiDPI, visual timig, text rendering and lots of other things is just much better.

Yes, because now you are switching to windowed mode instead of fullscreen mode. Now with the downside that visual presentation timing / timestamping is almost certainly shot.

Ok. If you’d have any further questions you’d need to buy another support membership, or we’d extend the current one with the extra hour packages for 300 Euros per started hour, unless your next question only happens in a couple of months, when the various discounts kick in.

Have a nice weekend,