Displaying a matlab figure as a texture in PTB

Hi,
I would like to display a figure in PTB to give the participant feedback about their performance.

I do create an invisible figure in Matlab, convert it with getFrame into an image, and create a PTB texture from that.

I experience a strange problem, that old textures are redisplayed in the Psychtoolbox window when I use getFrame to create an updated figure.

Do you have any advice on how I could work around this? Any other way in Matlab to create that figure? any other way to convert that figure into an image?

Thanks a lot for your help!

Best,
Antonius

System:
Windows 10
ATI graphics
Matlab 2019b
PTB 3.0.16

The formulation is a bit confusing: are you sure that getFrame gives you an updated figure? For debug, save them all to disk as well (or so) so you can verify that. Else, note that make texture will return a new texture id each time you upload. make sure you use that updated id

Hi,
I’m very sorry for the confusing formulation. The update is in fact an entirely new figure, I close the old figure in Matlab and I close the texture, too. Still, very surprisingly, the old texture reappears briefly before the new texture. So I assume it is related to the use of getFrame (on a new, independent figure). The same thing happens when I’m not using getFrame, but “saveas” the figure as an image and load it, but I assume that Matlab is internally doing something similar to getFrame, when saving.

Thanks!

can you provide minimal example code?

What do you mean with reappears briefly? Where does it reappear if Psychtoolbox covers the whole monitor with its own window? Can you show a minimal code sample that demonstrates the problem?

Hi,
This is a minimal demo:
https://www.dropbox.com/s/00zdzvd6vhrflzc/texture_error_minimal_example.m?dl=1

It creates and shows a plot, shows a line and shows a second plot.

I also did a video recording of the screen:

There are 2 problems:

  1. The psychtoolbox window disappears briefly when I create a figure for the first time (the desktop flashes)
  2. the first figure is redisplayed briefly before the second figure is displayed (it looks more that this is somehow a copy of the psychtoolbox window at the time point when I show the first figure and the psychtoolbox screen disappears briefly again when I create the second figure, but instead of flashing the Desktop, the old window is flashed).

It is a fresh install of Windows 10, btw. I have not had that problem under Windows 7.

Thanks a lot for your help!

Best,
Antonius

Thanks, the video is very helpful. Thanks for the code. It looks fine.
Running it works as expected for me (on Windows 10) I’m afraid, I
cannot reproduce what you see in your video (on Matlab 2019b).
The figure opening line can be simplified a little (but should not
make a difference):

f = figure('Visible', 'off'); clf; set(0, 'currentfigure', f);

Cheers,
Dee

Hi,
I was able to fix the issue by starting Matlab in software OpenGL mode! (-softwareopengl flag in a shortcut to Matlab). It runs as expected now.

That’s not a good solution if you need any timing precision or performance or more than basic functionality in PTB, as the software renderer won’t support that.

What you could try is set the ‘Renderer’ property for your plots to ‘painters’ to switch away from the OpenGL plotting for your figures only, if this is some bug in Matlab’s OpenGL plotting implementation causing weird interactions with PTB’s OpenGL use. Given that your figures are simple and plotting them is not time-critical the good ol’ painters algorithm should be sufficient.

That said, your script worked fine on R2019b + macOS and Octave 4.4 (with graphics_toolkit(‘qt’)) on Linux. And apparently also on Dee’s Windows 10 + R2019b. This suggests it is some oddity on your machine.

Works fine here too on Ubuntu 19.10+AMD WX5100 and an iMac… How about adding drawnow as well after the plot to force MATLAB’s drawing pipline to update?

Thank you, this did the trick! So the updated line for opening the figure is:

f = figure('Visible', 'off', 'Renderer', 'painters'); clf; set(0, 'currentfigure', f); 

Thanks again!