OpenGL and print

3 views (last 30 days)
Brian
Brian on 20 Dec 2011
Answered: Catherine on 11 Nov 2014
I've searched the blogs and answers but haven't found a satisfactory answer except that there is no satisfactory answer... so i'll ask here just to check. I am running R2011a 64bit Ubuntu O/S, fyi.
I am making a figure that uses transparency and was using jbfill from the file exchange. The script is great and produces a nice looking screen figure. However, when I print the figure to a file using print('-dpsc2','-r300','example.ps'), the ps file is total junk when using transparency<1 (in jbfill) and the ps file is fine when transparency is off (=1 in jbfill). seems like OpenGL is the problem. Is there any additional settings I can use to successfully print a figure with transparency (ie. with OpenGL) to a postscript or other file type? here's a sample script based on something in jbfill.m:
a=rand(1,20);
b=a+2*rand(1,20);
x=1:20;
% no transparency, ps file is fine
figure(1)
[ph,msg]=jbfill(x,a,b,'b','b',0,1);
print('-dpsc2','-r300','example1.ps');
% transparency, ps file is total junk
figure(2)
[ph,msg]=jbfill(x,a,b,'b','b',0,0.5);
print('-dpsc2','-r300','example2.ps');
  1 Comment
Oliver Woodford
Oliver Woodford on 24 Dec 2011
I would rename the question "Exporting figures with transparency as vector graphics" as it is more informative.

Sign in to comment.

Answers (6)

Walter Roberson
Walter Roberson on 20 Dec 2011
Transparency like you would like to use is not supported by Postscript. See http://en.wikipedia.org/wiki/Transparency_%28graphic%29#Transparency_in_PostScript
Meanwhile, have you tried Oliver's FEX contribution export_fig ?
  1 Comment
Brian
Brian on 20 Dec 2011
thanks for the pointer to export_fig. i'll test to see if it resolves my question and post back.

Sign in to comment.


Brian
Brian on 20 Dec 2011
export_fig seems to have a known and unresolved issue when transparency is used (via OpenGL). one workaround that i haven't tried might be to combine 2 transparent background PNGs together (with two different plots on the same axes) and see how it looks. sure would be nice to publication quality figures with transparency in the plot itself.
  1 Comment
Walter Roberson
Walter Roberson on 20 Dec 2011
The only known issue I see on that page is that transparency is not supported for the painters renderer. It isn't supported for zbuffer either but the page doesn't mention that. The portion of the page describing the -transparency flag indicates that you can use full blended transparency if you are exporting to PNG files (using OpenGL renderer)

Sign in to comment.


Brian
Brian on 21 Dec 2011
thanks for the reply. it seems like there are 2 levels of transparency that are relavent here: 1. background transparency and 2. filled area or plot line transparency (such that the shape or line of one plot can be seen behind the other). export_fig addresses 1, with the issues regarding at least the painters and zbuffer renderer. jbfill addresses 2 as suggested by the sample image on the exchange site.
the problem is that though jbfill (and other scripts) can produce plot transparency, there is no obvious way to print that figure to a file. export_fig does not seem to be able to print a figure with plot transparency. an odd side note is that i've had multiple crashes on my Ubuntu box when trying to print these OpenGL/plot transparency figures (6 GB RAM) - here's the script i'm using (noting that there are comments about example2b and example2c regarding the crashes which may or may not be O/S related)
function [] = ShowTransparencyProblem()
a=rand(1,20);
b=a+2*rand(1,20);
c=a+2*rand(1,20);
x=1:20;
% no transparency, png file is fine
figure(1)
[ph,msg]=jbfill(x,a,b,'b','b',1,1);
hold on
[ph,msg]=jbfill(x,a,c,'r','r',0,1);
print('-dpng','-r300','example1a.png');
export_fig example1b -png -transparent
% transparency, png file is total junk
figure(2)
[ph,msg]=jbfill(x,a,b,'b','b',1,0.5);
hold on
[ph,msg]=jbfill(x,a,c,'r','r',0,0.5);
print('-dpng','-r300','example2a.png');
% uncomment only one of the next lines. otherwise if there are
% two export_fig calls in a row, the entire system crashes.
% export_fig example2b -png
export_fig example2c -png -transparent
% matlab still exits on a fatal error after executing 'exit' when more than
% one export_fig -transparent is called in the function as a whole (ie. if
% export_fig example1b -png -transparent is uncommented along with
% export_fig example2c -png -transparent)
  7 Comments
Walter Roberson
Walter Roberson on 21 Dec 2011
That doesn't happen to mention the card model of your card. When I poke around the FireGL drivers, it appears the drivers are generally in the 8 series of versions, and it appears there is a beta version from January,
http://support.amd.com/us/gpudownload/fire/Pages/fire_beta_linux.aspx?type=2.4.3;2.4.5;2.4.7&product=2.4.3.3.2.3.17&lang=us&rev=8.801%20Beta&ostype=Linux%20x86_64
reference page http://support.amd.com/us/psearch/Pages/psearch.aspx?type=2.4.3%3b2.4.5%3b2.4.7&product=2.4.3.3.2.3.17&contentType=GPU+Download+Detail&ostype=Linux+x86_64&keywords=&items=20
If you are using the most recent driver, perhaps you could consider installing Mesa ?
Brian
Brian on 21 Dec 2011
i'll explore this and see if it works. thanks!

Sign in to comment.


Oliver Woodford
Oliver Woodford on 24 Dec 2011
To get transparency in vector graphics output, export your figure to an SVG file. Then convert to any other vector format you want using an external application such as Inkscape.

Lisandro
Lisandro on 23 Sep 2014
Hi, I had the same issue (I could print the figures using 'opengl software' but I couldn't with 'opengl hardware' in Matlab) and the problem was solved when I updated the video drivers
In my case I was using Ubuntu 12.04 (and afterwards 14.04) with an Intel Ivy Bridge. I downloaded and installed Mesa plus the Intel graphics Downloader manager (it's in the Ubuntu repository).
The problem was solved after I upgraded the drivers to their latest version.
Hope this helps
Best

Catherine
Catherine on 11 Nov 2014
Hi,
I had a similar problem trying to export figures with transparency (patch objects with the FaceAlpha property set to 0.5 for instance) in a PNG format with export_fig.
I filed a support request at MathWorks and the thing that resolved the issue was to set the OpenGL option 'software' to 'true' before doing anything else.
So just after startup, I type :
>> opengl software
And the call to export_fig works fine. I get a PNG file with transparency.
Hope this can help!

Categories

Find more on Graphics Performance in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!