-
Notifications
You must be signed in to change notification settings - Fork 1
/
gl2ps.tex
1131 lines (974 loc) · 46.6 KB
/
gl2ps.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
%
% GL2PS, an OpenGL to PostScript Printing Library
% Copyright (C) 1999-2017 C. Geuzaine
%
% This program is free software; you can redistribute it and/or
% modify it under the terms of either:
%
% a) the GNU Library General Public License as published by the Free
% Software Foundation, either version 2 of the License, or (at your
% option) any later version; or
%
% b) the GL2PS License as published by Christophe Geuzaine, either
% version 2 of the License, or (at your option) any later version.
%
% This program is distributed in the hope that it will be useful, but
% WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See either
% the GNU Library General Public License or the GL2PS License for
% more details.
%
% You should have received a copy of the GNU Library General Public
% License along with this library in the file named "COPYING.LGPL";
% if not, write to the Free Software Foundation, Inc., 51 Franklin
% Street, Fifth Floor, Boston, MA 02110-1301, USA.
%
% You should have received a copy of the GL2PS License with this
% library in the file named "COPYING.GL2PS"; if not, I will be glad
% to provide one.
%
% For the latest info about gl2ps and a full list of contributors,
% see http://www.geuz.org/gl2ps/.
%
% Please report all bugs and problems to <[email protected]>.
%%tth: \begin{html}<meta name="viewport" content="width=device-width, initial-scale=1.0"> <link href="http://geuz.org/geuz.css" rel="stylesheet" type="text/css"> <style type="text/css"> h3 { border-bottom: 0; }</style><title>GL2PS: an OpenGL to PostScript printing library</title>\end{html}
\documentclass[10pt]{article}
\pagestyle{headings}
\setcounter{tocdepth}{2}
\sloppypar
\usepackage[colorlinks=true,urlcolor=blue]{hyperref}
\usepackage{graphicx}
\ifx\pdfoutput\undefined\else
\pdfinfo{
/Title (GL2PS: an OpenGL to PostScript printing library)
/Author (Christophe Geuzaine)
/Subject (Documentation)
/Keywords (OpenGL, PostScript, PDF, SVG, Printing)
}
\fi
\newcommand{\dd}{\begingroup\Url}
\newcommand{\email}[2]{\href{mailto:#2}{#1}}
\newcommand{\noemail}[2]{#1}
%%tth: \def\dd#1{\textmd{\texttt{#1}}}
\begin{document}
\title{GL2PS: an OpenGL to PostScript printing library}
\author{Christophe Geuzaine}
\maketitle
\special{html:<center>
<p>
<a href="http://geuz.org/gl2ps/outBspCulled.ps"><img width="12%"
src="http://geuz.org/gl2ps/outThumbnail.png" alt="PS"></a>
<a href="http://geuz.org/gl2ps/outBspCulled.eps"><img width="12%"
src="http://geuz.org/gl2ps/outThumbnail.png" alt="EPS"></a>
<a href="http://geuz.org/gl2ps/outBspCulledCompressed.pdf"><img width="12%"
src="http://geuz.org/gl2ps/outThumbnail.png" alt="PDF"></a>
<a href="http://geuz.org/gl2ps/outBspCulled.svg"><img width="12%"
src="http://geuz.org/gl2ps/outThumbnail.png" alt="SVG"></a>
</p>
<p><small><em>Example:
<a href="http://geuz.org/gl2ps/outBspCulled.ps">PS</a>,
<a href="http://geuz.org/gl2ps/outBspCulled.eps">EPS</a>,
<a href="http://geuz.org/gl2ps/outBspCulledCompressed.pdf">PDF</a> and
<a href="http://geuz.org/gl2ps/outBspCulled.svg">SVG</a>
files created with the <tt>gl2psTest.c</tt> demo provided in the
distribution. This illustrates the handling of smooth shading,
intersecting primitives, line stippling, vector text rendering,
multiple viewports and mixed vector/bitmap output. Compare with a
<a href="http://geuz.org/gl2ps/outBitmap.png">PNG</a> screenshot of
the OpenGL window.</em></small>
</p>
</center>
<h2>Download</h2>
The latest stable version of GL2PS is <a
href="http://geuz.org/gl2ps/src/gl2ps-1.4.1.tgz">gl2ps-1.4.1.tgz</a>. Older
versions and source snapshots are available <a
href="http://geuz.org/gl2ps/src/">here</a>. For access to the Git repository use:
'<code>git clone <a href="http://gitlab.onelab.info/gl2ps/gl2ps.git"
>http://gitlab.onelab.info/gl2ps/gl2ps.git</a></code>'.
<p>
For questions and discussions about GL2PS see the <a
href="http://geuz.org/mailman/listinfo/gl2ps/">gl2ps mailing list</a>. If you
think you have found a bug you can also file a report directly <a
href="http://gitlab.onelab.info/gl2ps/gl2ps/issues">here</a>.
You can also subscribe to the <a
href="http://geuz.org/mailman/listinfo/gl2ps-announce/">gl2ps-announce</a>
mailing list to be notified automatically when a new version of GL2PS is
released.
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<p>
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="[email protected]">
<input type="hidden" name="item_name" value="GL2PS donation">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="currency_code" value="EUR">
<input type="hidden" name="tax" value="0">
To help fund GL2PS development, you can make a
<input type="submit" value="PayPal" style="display:inline;">
donation.
</p>
</form>
<h2>Documentation</h2>}
\tableofcontents
\section{Introduction}
GL2PS is a C library providing high quality vector output for any OpenGL
application. The main difference between GL2PS and other similar libraries
(see section~\ref{sec:links}) is the use of sorting algorithms capable of
handling intersecting and stretched polygons, as well as non manifold
objects. GL2PS provides advanced smooth shading and text rendering, culling
of invisible primitives, mixed vector/bitmap output, and much more...
GL2PS can currently create PostScript (PS), Encapsulated PostScript
(EPS), Portable Document Format (PDF) and Scalable Vector Graphics (SVG)
files, as well as \LaTeX\ files for the text fragments. GL2PS also
provides limited, experimental support for Portable LaTeX Graphics
(PGF). Adding new vector output formats should be relatively easy; you
can also use the excellent \href{http://www.pstoedit.net}{pstoedit}
program to transform the PostScript files generated by GL2PS into many
other vector formats such as xfig, cgm, wmf, etc.
GL2PS is available at \url{http://www.geuz.org/gl2ps/} and is released under
the GNU Library General Public License (see
\href{http://www.geuz.org/gl2ps/COPYING.LGPL}{COPYING.LGPL}). GL2PS can also
be used under an alternative license that allows (amongst other things, and
under certain conditions) for static linking with closed-source software
(see \href{http://www.geuz.org/gl2ps/COPYING.GL2PS}{COPYING.GL2PS}). Any
corrections, questions or suggestions should be e-mailed to the GL2PS
mailing list \email{[email protected]}{[email protected]}.
The interface consists of seventeen functions, all beginning with the
prefix \dd{gl2ps}. All the data structures and the symbolic constants
peculiar to GL2PS begin with \dd{GL2PS}.
\section{Usage}
% -------------------------------------------------------------------------
\subsection{\texttt{gl2psBeginPage} and \texttt{gl2psEndPage}}
\label{sec:gl2psBeginPage}
\subsubsection{Specification}
\begin{verbatim}
GLint gl2psBeginPage( const char *title, const char *producer,
GLint viewport[4],
GLint format, GLint sort, GLint options,
GLint colormode, GLint colorsize,
GL2PSrgba *colortable,
GLint nr, GLint ng, GLint nb,
GLint buffersize, FILE *stream,
const char *filename )
\end{verbatim}
\begin{verbatim}
GLint gl2psEndPage( void )
\end{verbatim}
\subsubsection{Description and arguments}
\dd{gl2psBeginPage} and \dd{gl2psEndPage} delimit the OpenGL commands that
will be caught in the feedback buffer (see section~\ref{sec:limitations})
and output to \dd{stream}. The arguments given to \dd{gl2psBeginPage}
determine the way primitives are handled:
\begin{description}
\item[\dd{title}] Specifies the plot title. For PostScript output, this
string is placed in the \texttt{\%\%Title} field.
\item[\dd{producer}] Specifies the plot producer. For PostScript output,
this string is placed in the \texttt{\%\%For} field.
\item[\dd{viewport}] Specifies the plot viewport. The viewport can for
example be obtained with a call to \dd{glGetIntegerv(GL_VIEWPORT,
viewport)}. This argument is ignored if the
\dd{GL2PS_USE_CURRENT_VIEWPORT} option is set.
\item[\dd{format}] Specifies the output format, chosen among:
\begin{description}
\item[\dd{GL2PS_PS}] The output stream will be in PostScript format.
\item[\dd{GL2PS_EPS}] The output stream will be in Encapsulated PostScript
format.
\item[\dd{GL2PS_PDF}] The output stream will be in Portable Document Format.
\item[\dd{GL2PS_TEX}] The output will be a \LaTeX\ file containing only the
text strings of the plot (cf.\ section~\ref{sec:gl2psText}), as well as an
\verb+\includegraphics+ command including a graphic file having the same
basename as \dd{filename}.\footnote{The two steps to generate a \LaTeX\
plot with GL2PS are thus:
\begin{enumerate}
\item generate the PostScript or PDF file (e.g.\ \dd{file.ps} or
\dd{file.pdf}) with no text strings, using the \dd{GL2PS_PS},
\dd{GL2PS_EPS} or \dd{GL2PS_PDF} format combined with the
\dd{GL2PS_NO_TEXT} option;
\item generate the \LaTeX\ file \dd{file.tex}, using the \dd{GL2PS_TEX}
format and specifying \dd{file.tex} as the \dd{filename} argument to
\dd{gl2psBeginPage}.
\end{enumerate}
You can of course combine the \LaTeX\ output with other graphic formats
than PostScript or PDF. For example, you could export an image in JPEG
or PNG format and use pdf\LaTeX\ with the same \dd{file.tex}.}
\item[\dd{GL2PS_SVG}] The output stream will be in Scalable Vector
Graphics format.
\item[\dd{GL2PS_PGF}] (Experimental) The output stream will be in
Portable LaTeX Graphics format.
\end{description}
\item[\dd{sort}] Specifies the sorting algorithm, chosen among:
\begin{description}
\item[\dd{GL2PS_NO_SORT}] The primitives are not sorted, and are output in
\dd{stream} in the order they appear in the feedback buffer. This is
sufficient for two-dimensional scenes.
\item[\dd{GL2PS_SIMPLE_SORT}] The primitives are sorted according to their
barycenter. This can be sufficient for simple three-dimensional scenes
and/or when correctness is not crucial.
\item[\dd{GL2PS_BSP_SORT}] The primitives are inserted in a Binary Space
Partition (BSP) tree. The tree is then traversed back to front in a
painter-like algorithm. This should be used whenever an accurate rendering
of a three-dimensional scene is sought. Beware that this algorithm
requires a lot more computational time (and memory) than the simple
barycentric sort.
\end{description}
\item[\dd{options}] Sets global plot options, chosen among (multiple options
can be combined with the bitwise inclusive OR symbol \dd{|}):
\begin{description}
\item[\dd{GL2PS_NONE}] No option.
\item[\dd{GL2PS_DRAW_BACKGROUND}] The background frame is drawn in the
plot.
\item[\dd{GL2PS_SIMPLE_LINE_OFFSET}] A small offset is added in the z-buffer
to all the lines in the plot. This is a simplified version of the
\dd{GL2PS_POLYGON_OFFSET_FILL} functionality
(cf. section~\ref{sec:gl2psEnable}), putting all the lines of the rendered
image slightly in front of their actual position. This thus performs a
simple anti-aliasing solution, e.g.\ for finite-element-like meshes.
\item[\dd{GL2PS_SILENT}] All the messages written by GL2PS on the error
stream are suppressed.
\item[\dd{GL2PS_BEST_ROOT}] The construction of the BSP tree is optimized by
choosing the root primitives leading to the minimum number of splits.
\item[\dd{GL2PS_NO_TEXT}] All the text strings are suppressed from
the output stream. This is useful to produce the image part of a \LaTeX\ plot.
\item[\dd{GL2PS_NO_PIXMAP}] All the pixmaps are suppressed from the output
stream.
\item[\dd{GL2PS_LANDSCAPE}] The plot is output in landscape orientation
instead of portrait.
\item[\dd{GL2PS_NO_PS3_SHADING}] (for PostScript output only) No use is made
of the \dd{shfill} PostScript level 3 operator. Using \dd{shfill} enhances
the plotting of smooth shaded primitives but can lead to problems when
converting PostScript files into PDF files. See also options \dd{nr},
\dd{ng}, \dd{nb} below.
\item[\dd{GL2PS_NO_BLENDING}] Blending (transparency) is disabled
alltogether (regardless of the current \dd{GL_BLEND} or \dd{GL2PS_BLEND}
status).
\item[\dd{GL2PS_OCCLUSION_CULL}] All the hidden polygons are removed from
the output, thus substantially reducing the size of the output file.
\item[\dd{GL2PS_USE_CURRENT_VIEWPORT}] The current OpenGL viewport is used
instead of \dd{viewport}.
\item[\dd{GL2PS_TIGHT_BOUNDING_BOX}] The viewport is ignored and the
the plot is generated with a tight bounding box, i.e., a bounding
box enclosing as tightly as possible all the OpenGL entities in the
scene.
\item[\dd{GL2PS_COMPRESS}] The output stream is compressed. For this option
to take effect you need to compile GL2PS with \dd{HAVE_ZLIB},
\dd{HAVE_LIBZ} or \dd{GL2PS_HAVE_ZLIB} defined, and link the executable
with the zlib library (\url{http://www.gzip.org/zlib/}).
PostScript or SVG files generated with this option turned on are
simply compressed ``as a whole'', i.e., they are identical to
regular PostScript or SVG files compressed with the gzip
program. For PDF files the compression is done ``locally'' for each
group of primitives, in accordance with the official PDF
specification.
\item[\dd{GL2PS_NO_OPENGL_CONTEXT}] GL2PS will not query an OpenGL
context for information, nor will it create/parse a feedback
buffer. This is required for newer OpenGL versions that have
deprecated the feedback render mode. Using GL2PS in this mode
requires all geometry to be added manually using
\dd{gl2psAddPolyPrimitive} (see \url{https://open.gl/feedback} for a
replacement to the deprecated OpenGL feedback
buffers). \dd{gl2psText}, \dd{gl2psTextOpt}, \dd{gl2psDrawPixels},
and \dd{gl2psSpecial} are still usable, but require the use of
\dd{gl2psForceRasterPos} to set the raster position.
This option is incompatible with \dd{GL2PS_DRAW_BACKGROUND} and
\dd{GL2PS_USE_CURRENT_VIEWPORT}, and requires \dd{GL2PS_NO_BLENDING}
to be set. The \dd{gl2psBeginPage} \dd{colormode} must be set to
\dd{GL_RGBA} if this option is enabled. If these restrictions are
not met, a runtime error will be reported and \dd{gl2psBeginPage} /
\dd{gl2psSetOptions} will return \dd{GL2PS_ERROR}.
\end{description}
\item[\dd{colormode}] Specifies the color mode: \dd{GL_RGBA} or
\dd{GL_COLOR_INDEX}.
\item[\dd{colorsize}] Specifies the size of the colormap if \dd{colormode}
is \dd{GL_COLOR_INDEX}.
\item[\dd{colortable}] Contains the colormap if \dd{colormode} is
\dd{GL_COLOR_INDEX}. This colormap must contain \dd{colorsize} elements of
type \dd{GL2PSrgba}.
\item[\dd{nr}, \dd{ng}, \dd{nb}] (for PostScript and SVG output only)
Controls the number of flat-shaded \mbox{(sub-)triangles} used to
approximate a smooth-shaded triangle. (For PostScript output, this
is only used when the \dd{shfill} operator is not supported by the
system or when the \dd{GL2PS_NO_PS3_SHADING} option is set.) The
arguments \dd{nr}, \dd{ng} and \dd{nb} specify the number of values
used for interpolating the full range of red, green and blue color
components; that is, a triangle is recursively subdivided until the
color difference between two of its vertices is smaller that
$1/\mathtt{nr}$ for the red component, $1/\mathtt{ng}$ for the green
component and $1/\mathtt{nb}$ for the blue component. If the
arguments are set to zero, default values are used.
\item[\dd{buffersize}] Specifies the size of the feedback buffer.
\item[\dd{stream}] Specifies the stream to which data is printed.
\item[\dd{filename}] (for \LaTeX\ output only) Specifies a name for
the stream to which data is printed.
\end{description}
\subsubsection{Return value}
\noindent\dd{gl2psBeginPage} returns:
\begin{description}
\item[\dd{GL2PS_ERROR}] if an error occurred;
\item[\dd{GL2PS_SUCCESS}] otherwise.
\end{description}
\noindent\dd{gl2psEndPage} returns:
\begin{description}
\item[\dd{GL2PS_NO_FEEDBACK}] if the feedback buffer is empty;
\item[\dd{GL2PS_OVERFLOW}] if the size of the feedback buffer given to
\dd{gl2psBeginPage} is not large enough;
\item[\dd{GL2PS_UNINITIALIZED}] if \dd{gl2psEndPage} is called when the
library is not initialized (e.g.\ if \dd{gl2psEndPage} is called before
\dd{gl2psBeginPage});
\item[\dd{GL2PS_ERROR}] if an error occurred;
\item[\dd{GL2PS_SUCCESS}] otherwise.
\end{description}
% -------------------------------------------------------------------------
\subsection{\texttt{gl2psSorting}}
\label{sec:gl2psSorting}
\subsubsection{Specification}
\begin{verbatim}
GLint gl2psSorting( GLint value )
\end{verbatim}
\subsubsection{Description and arguments}
\dd{gl2psSorting} specify the sorting algorithm for subsequent viewport(s).
This function is useful in order to set different sorting algorithms
from one viewport to another.
\subsubsection{Return value}
\noindent\dd{gl2psSorting} returns:
\begin{description}
\item[\dd{GL2PS_UNINITIALIZED}] if the library is not initialized;
\item[\dd{GL2PS_ERROR}] if an error occurred;
\item[\dd{GL2PS_SUCCESS}] otherwise.
\end{description}
% -------------------------------------------------------------------------
\subsection{\texttt{gl2psText} and \texttt{gl2psTextOpt}}
\label{sec:gl2psText}
\subsubsection{Specification}
\begin{verbatim}
GLint gl2psText( const char *string, const char *fontname,
GLint fontsize )
GLint gl2psTextOpt( const char *string, const char *fontname,
GLint fontsize, GLint align, GLfloat angle )
\end{verbatim}
\subsubsection{Description and arguments}
\dd{gl2psText} and \dd{gl2psTextOpt} permit to include a text string
in the output stream. The string is inserted at the current raster
position (set by one of the \dd{glRasterPos} OpenGL commands). Beware
that text will be sorted according to the current raster position
only. The arguments are:
\begin{description}
\item[\dd{string}] Specifies the text string to print.
\item[\dd{fontname}] Specifies the PostScript name of a valid Type 1
font\footnote{The names of the 14 standard Type 1 fonts are as
follows: \dd{Times-Roman}, \dd{Times-Bold}, \dd{Times-Italic},
\dd{Times-BoldItalic}, \dd{Helvetica}, \dd{Helvetica-Bold},
\dd{Helvetica-Oblique}, \dd{Helvetica-BoldOblique}, \dd{Courier},
\dd{Courier-Bold}, \dd{Courier-Oblique}, \dd{Courier-BoldOblique},
\dd{Symbol} and \dd{ZapfDingbats}. These fonts, or their font
metrics and suitable substitution fonts, are guaranteed to be
available to the viewer application. Using any other font will
result in a non-portable PostScript or PDF file, as GL2PS does not
include any font description in its output stream.}. This has no
effect for \LaTeX\ and PGF output.
\item[\dd{fontsize}] Specifies the size of the font.
\end{description}
The additional arguments for \dd{gl2psTextOpt} are:
\begin{description}
\item[\dd{align}] (for PostScript, \LaTeX\ and PGF output only)
Specifies the text string alignment with respect to the current
raster position. Valid choices are \dd{GL2PS_TEXT_C}
(center-center), \dd{GL2PS_TEXT_CL} (center-left),
\dd{GL2PS_TEXT_CR} (center-right), \dd{GL2PS_TEXT_B}
(bottom-center), \dd{GL2PS_TEXT_BL} (bottom-left) \dd{GL2PS_TEXT_BR}
(bottom-right), \dd{GL2PS_TEXT_T} (top-center), \dd{GL2PS_TEXT_TL}
(top-left) and \dd{GL2PS_TEXT_TR} (top-right). The default alignment
used by \dd{gl2psText} is \dd{GL2PS_TEXT_BL}.
\begin{verbatim}
+---+ +---+ +---+ +---+ +---+ +---+ +-o-+ o---+ +---o
| o | o | | o | | | | | | | | | | | |
+---+ +---+ +---+ +-o-+ o---+ +---o +---+ +---+ +---+
C CL CR B BL BR T TL TR
\end{verbatim}
\item[\dd{angle}] (for PostScript, \LaTeX\ and PGF output only)
Specifies a rotation angle for the text string (counter-clockwise,
in degrees).
\end{description}
\subsubsection{Return value}
\noindent\dd{gl2psText} and \dd{gl2psTextOpt} return:
\begin{description}
\item[\dd{GL2PS_UNINITIALIZED}] if \dd{string} is \dd{NULL} or if the
library is not initialized;
\item[\dd{GL2PS_ERROR}] if an error occurred;
\item[\dd{GL2PS_SUCCESS}] otherwise.
\end{description}
Note that gl2ps 1.3.8 introduces a variant of \dd{gl2psTextOpt}, called
\dd{gl2psTextOptColor}, which takes one additional arguement of type
\dd{GL2PSrgba}. This was introduced for systems which do not keep track of
the current raster color in feedback mode.
% -------------------------------------------------------------------------
\subsection{\texttt{gl2psDrawPixels}}
\label{sec:gl2psDrawPixels}
\subsubsection{Specification}
\begin{verbatim}
GLint gl2psDrawPixels( GLsizei width, GLsizei height,
GLint xorig, GLint yorig,
GLenum format, GLenum type,
const void *pixels )
\end{verbatim}
\subsubsection{Description and arguments}
\dd{gl2psDrawPixels} emulates the \dd{glDrawPixels} function, i.e.,
permits to embed bitmap images in the PostScript, PDF or SVG output.
To embed bitmaps in SVG output, GL2PS needs to be compiled with
\dd{HAVE_LIBPNG} or \dd{GL2PS_HAVE_LIBPNG} defined, and the executable
must be linked with the PNG library (\url{http://www.libpng.org}).
The bitmap image is inserted at the current raster position (set by
one of the \dd{glRasterPos} OpenGL commands). Beware that the image
will be sorted according to the position of the current raster
position only. The arguments are:
\begin{description}
\item[\dd{width}] Specifies the width of the image.
\item[\dd{height}] Specifies the height of the image.
\item[\dd{xorig}, \dd{yorig}] Specify the location of the origin in the
image. The origin is measured from the lower left corner of the image,
with right and up being the positive axes.
\item[\dd{format}] Specifies the format of the pixel data. \dd{GL_RGB} and
\dd{GL_RGBA} are the only values accepted at the moment.
\item[\dd{type}] Specifies the data type for pixels. \dd{GL_FLOAT} is the
only value accepted at the moment.
\item[\dd{pixels}] Specifies a pointer to the pixel data.
\end{description}
\subsubsection{Return value}
\noindent\dd{gl2psDrawPixels} returns:
\begin{description}
\item[\dd{GL2PS_UNINITIALIZED}] if \dd{pixels} is \dd{NULL} or if the
library is not initialized;
\item[\dd{GL2PS_ERROR}] if an error occurred;
\item[\dd{GL2PS_SUCCESS}] otherwise.
\end{description}
% -------------------------------------------------------------------------
\subsection{\texttt{gl2psSpecial}}
\label{sec:gl2psSpecial}
\subsubsection{Specification}
\begin{verbatim}
GLint gl2psSpecial( GLint format, const char *str )
\end{verbatim}
\subsubsection{Description and arguments}
\dd{gl2psSpecial} permits to output an arbitrary command string in an
output stream of a given format. The arguments are:
\begin{description}
\item[\dd{format}] Specifies the output format for which the special
string will be printed. If the stream format (specified with
\dd{gl2psBeginPage}, see Section~\ref{sec:gl2psBeginPage}) does not
match \dd{format}, the command has no effect.
\item[\dd{str}] Specifies the string to print.
\end{description}
\subsubsection{Return value}
\noindent\dd{gl2psSpecial} returns:
\begin{description}
\item[\dd{GL2PS_UNINITIALIZED}] if \dd{str} is \dd{NULL} or if the
library is not initialized;
\item[\dd{GL2PS_ERROR}] if an error occurred;
\item[\dd{GL2PS_SUCCESS}] otherwise.
\end{description}
% -------------------------------------------------------------------------
\subsection{\texttt{gl2psEnable} and \texttt{gl2psDisable}}
\label{sec:gl2psEnable}
\subsubsection{Specification}
\begin{verbatim}
GLint gl2psEnable( GLint mode )
\end{verbatim}
\begin{verbatim}
GLint gl2psDisable( GLint mode )
\end{verbatim}
\subsubsection{Description and arguments}
\dd{gl2psEnable} and \dd{gl2psDisable} delimit OpenGL commands to which a local
\dd{mode} is applied. These modes are:
\begin{description}
\item[\dd{GL2PS_LINE_STIPPLE}] Emulates the \dd{GL_LINE_STIPPLE}
functionality. The stippling pattern and repetition factor are taken
as the current values of the corresponding OpenGL stippling options
(set with \dd{glLineStipple}). You thus need to call
\dd{gl2psEnable(GL2PS_LINE_STIPPLE)} \emph{after} calling
\dd{glLineStipple(factor, pattern)}.
\item[\dd{GL2PS_POLYGON_OFFSET_FILL}] Emulates the
\dd{GL_POLYGON_OFFSET_FILL} functionality. The value of the offset is
taken as the current value of the corresponding OpenGL offset (set with
\dd{glPolygonOffset}).
\item[\dd{GL2PS_BLEND}] Emulates the \dd{GL_BLEND} functionality.
(Warning: this might change in future releases.)
\item[\dd{GL2PS_POLYGON_BOUNDARY}] Not implemented yet.
\end{description}
\subsubsection{Return value}
\noindent\dd{gl2psEnable} and \dd{gl2psDisable} return:
\begin{description}
\item[\dd{GL2PS_UNINITIALIZED}] if the library is not initialized;
\item[\dd{GL2PS_ERROR}] if an error occurred;
\item[\dd{GL2PS_SUCCESS}] otherwise.
\end{description}
% -------------------------------------------------------------------------
\subsection{\texttt{gl2psPointSize}, \texttt{gl2psLineWidth},
\texttt{gl2psLineCap} and \texttt{gl2psLineJoin}}
\label{sec:gl2psPointSize}
\subsubsection{Specification}
\begin{verbatim}
GLint gl2psPointSize( GLfloat value )
\end{verbatim}
\begin{verbatim}
GLint gl2psLineWidth( GLfloat value )
\end{verbatim}
\begin{verbatim}
GLint gl2psLineCap( GLint value )
\end{verbatim}
\begin{verbatim}
GLint gl2psLineJoin( GLint value )
\end{verbatim}
\subsubsection{Description and arguments}
\dd{gl2psPointSize} and \dd{gl2psLineWidth} emulate the standard
\dd{glPointSize} and the \dd{glLineWidth} functions. They are necessary
since the point sizes and line widths are not saved in the OpenGL feedback
buffer.
\dd{gl2psLineCap} and \dd{gl2psLineJoin} let you choose respectively
the shape of the lines ending and intersections (for line
strips). As those features are not part of OpenGL line options, the
output will look different from the corresponding OpenGL scene.
For \dd{gl2psLineCap} allowed values are \dd{GL2PS_LINE_CAP_BUTT}
(the default), \dd{GL2PS_LINE_CAP_ROUND} and \dd{GL2PS_LINE_CAP_SQUARE}. For
\dd{gl2psLineJoin} allowed values are \dd{GL2PS_LINE_JOIN_MITER}
(the default), \dd{GL2PS_LINE_JOIN_ROUND} and \dd{GL2PS_LINE_JOIN_BEVEL}.
\subsubsection{Return value}
\noindent\dd{gl2psPointSize}, \dd{gl2psLineWidth}, \dd{gl2psLineCap}
and \dd{gl2psLineJoin} return:
\begin{description}
\item[\dd{GL2PS_UNINITIALIZED}] if the library is not initialized;
\item[\dd{GL2PS_ERROR}] if an error occurred;
\item[\dd{GL2PS_SUCCESS}] otherwise.
\end{description}
% -------------------------------------------------------------------------
\subsection{\texttt{gl2psBlendFunc}}
\label{sec:gl2psBlendFunc}
\subsubsection{Specification}
\begin{verbatim}
GLint gl2psBlendFunc( GLenum sfactor, GLenum dfactor )
\end{verbatim}
\subsubsection{Description and arguments}
\dd{gl2psBlendFunc} emulates the \dd{glBlendFunc} function.
\subsubsection{Return value}
\noindent\dd{gl2psBlendFunc} returns:
\begin{description}
\item[\dd{GL2PS_UNINITIALIZED}] if the library is not initialized;
\item[\dd{GL2PS_WARNING}] if the blending mode is not (yet) supported;
\item[\dd{GL2PS_SUCCESS}] otherwise.
\end{description}
% -------------------------------------------------------------------------
\subsection{\texttt{gl2psBeginViewport} and \texttt{gl2psEndViewport}}
\label{sec:gl2psBeginViewport}
\subsubsection{Specification}
\begin{verbatim}
GLint gl2psBeginViewport ( GLint viewport[4] )
\end{verbatim}
\begin{verbatim}
GLint gl2psEndViewport ( void )
\end{verbatim}
\subsubsection{Description and arguments}
\dd{gl2psBeginViewport} and \dd{gl2psEndViewport} permit to output different
viewports\footnote{See the description of \dd{glViewport} and \dd{glScissor}
in the OpenGL documentation.} in the output stream. Each viewport is sorted
separately and has its own background frame. The argument given to
\dd{gl2psBeginViewport} specifies the viewport (obtained for example with a
call to \dd{glGetIntegerv(GL_VIEWPORT, viewport)}).
\subsubsection{Return value}
\noindent\dd{gl2psBeginViewport} returns:
\begin{description}
\item[\dd{GL2PS_UNINITIALIZED}] if the library is not initialized;
\item[\dd{GL2PS_ERROR}] if an error occurred;
\item[\dd{GL2PS_SUCCESS}] otherwise.
\end{description}
\noindent\dd{gl2psEndViewport} returns:
\begin{description}
\item[\dd{GL2PS_NO_FEEDBACK}] if the feedback buffer is empty;
\item[\dd{GL2PS_OVERFLOW}] if the size of the feedback buffer given to
\dd{gl2psBeginPage} is not large enough;
\item[\dd{GL2PS_UNINITIALIZED}] if \dd{gl2psEndViewport} is called when the
library is not initialized;
\item[\dd{GL2PS_ERROR}] if an error occurred;
\item[\dd{GL2PS_SUCCESS}] otherwise.
\end{description}
% -------------------------------------------------------------------------
\subsection{\texttt{gl2psSetOptions} and \texttt{gl2psGetOptions}}
\label{sec:gl2psSetOptions}
\subsubsection{Specification}
\begin{verbatim}
GLint gl2psSetOptions ( GLint options )
GLint gl2psGetOptions ( GLint *options )
\end{verbatim}
\subsubsection{Description and arguments}
\dd{gl2psSetOptions} permits to change the global options initially
set using the \dd{options} argument to \dd{gl2psBeginPage} (see
section~\ref{sec:gl2psBeginPage}). \dd{gl2psGetOptions} permits to
retrieve the current options.
\dd{gl2psSetOptions} can for example be used to force GL2PS to print
the background for selected viewports, by setting/unsetting
\dd{GL2PS_DRAW_BACKGROUND} before calling \dd{gl2psBeginViewport}.
\subsubsection{Return value}
\noindent\dd{gl2psSetOptions} and \dd{gl2psGetOptions} return:
\begin{description}
\item[\dd{GL2PS_UNINITIALIZED}] if the library is not initialized;
\item[\dd{GL2PS_ERROR}] if an error occurs;
\item[\dd{GL2PS_SUCCESS}] otherwise.
\end{description}
% -------------------------------------------------------------------------
\section{Example}
Here is a typical calling sequence to produce BSP sorted PostScript output
in the file \dd{"MyFile"}, with all the lines slightly shifted front in the
z-buffer and all invisible primitives removed to reduce the size of the
output file. The \dd{draw()} function contains all the OpenGL commands.
\begin{verbatim}
FILE *fp = fopen("MyFile", "wb");
GLint buffsize = 0, state = GL2PS_OVERFLOW;
GLint viewport[4];
glGetIntegerv(GL_VIEWPORT, viewport);
while( state == GL2PS_OVERFLOW ){
buffsize += 1024*1024;
gl2psBeginPage ( "MyTitle", "MySoftware", viewport,
GL2PS_EPS, GL2PS_BSP_SORT, GL2PS_SILENT |
GL2PS_SIMPLE_LINE_OFFSET | GL2PS_NO_BLENDING |
GL2PS_OCCLUSION_CULL | GL2PS_BEST_ROOT,
GL_RGBA, 0, NULL, 0, 0, 0, buffsize,
fp, "MyFile" );
draw();
state = gl2psEndPage();
}
fclose(fp);
\end{verbatim}
\noindent To output the text \dd{"MyText"} at the current raster position, the
\dd{draw()} function should contain something like:
\begin{verbatim}
gl2psText("MyText", "Courier", 12);
\end{verbatim}
Complete example programs (\dd{gl2psTestSimple.c} and \dd{gl2psTest.c})
are included in the distribution.
%\begin{figure}
%\scalebox{0.85}{\input{outLatex.tex}}
%\caption{Sample output of the test program}
%\end{figure}
\section{Tips and tricks}
\label{sec:tips}
Here are, in no particular order, some useful tips and solutions to common
problems:
\begin{itemize}
\item For PDF (both compressed and non-compressed) and for compressed
PostScript and SVG output, files should always be opened in binary
mode, i.e., with \dd{fopen(..., "wb")}, instead of \dd{fopen(...,
"w")}.
\item Blending is not yet very well supported by many viewers/printers. To
disable blending entirely, add \dd{GL2PS_NO_BLENDING} to the list of
options passed to \dd{gl2psBeginPage}.
\item Make sure that localization is turned off when using GL2PS, via:
\begin{verbatim}
unsigned char *oldlocale = setlocale(LC_NUMERIC, "C");
/* gl2ps drawing stuff */
setlocale(LC_NUMERIC, oldlocale);
\end{verbatim}
French or German localizations would for example lead to corrupted output
files, as they represent the decimal point by a comma.
\item If you plan to convert PostScript files into PDF files, you may need
to disable the use of the Level 3 PostScript \dd{shfill} operator, i.e.,
add \dd{GL2PS_NO_PS3_SHADING} to the list of options passed to
\dd{gl2psBeginPage}. (Note that you can also edit the output file \emph{a
posteriori}---just set \dd{/tryPS3shading} to \dd{false} in the
PostScript file header.) The best way to generate PDF files is of course
to set the \dd{format} argument to \dd{GL2PS_PDF} in the
\dd{gl2psBeginPage} call...
\item By default, GL2PS checks if blending is globally enabled in
\dd{gl2psBeginPage()}. To enable blending for selected primitives
only, you should use \dd{gl2psEnable(GL2PS_BLEND)} and
\dd{gl2psDisable(GL2PS_BLEND)} pairs around the OpenGL calls that
need blending. (Warning: this might change in future releases.)
\item \dd{gl2psEnable(GL2PS_LINE_STIPPLE)} uses the current values of
the OpenGL stippling options to compute the stippling pattern and
repetition factor. You thus need to call
\dd{gl2psEnable(GL2PS_LINE_STIPPLE)} \emph{after} calling
\dd{glLineStipple(factor, pattern)}.
\end{itemize}
\section{Limitations}
\label{sec:limitations}
GL2PS works by capturing the contents of the OpenGL feedback
buffer\footnote{See the description of \dd{glFeedbackBuffer} and
\dd{glRenderMode(GL_FEEDBACK)} in the OpenGL documentation.}. As such, all
the OpenGL operations applied in the pipeline after the creation of the
feedback buffer will be ignored or have to be duplicated by GL2PS (e.g.\
font/image rendering, polygon offset or line stippling---see
sections~\ref{sec:gl2psText}, \ref{sec:gl2psDrawPixels},
\ref{sec:gl2psEnable} and \ref{sec:gl2psPointSize}).
Other limitations include:
\begin{itemize}
\item
Rendering large and/or complicated scenes is slow and/or can lead to large
output files. This is normal: vector-based images are not destined to
replace bitmap images. They just offer an alternative when high quality
(especially for 2D and small 3D plots) and ease of manipulation (how do you
change the scale, the labels or the colors in a bitmap picture long after
the picture was produced, and without altering its quality?) are important.
\item
Transparency is only supported for PDF and SVG output.
\item
GL2PS does not support textures, fog effects, etc.
\end{itemize}
% Other implementation Notes:
%
% OpenGL feedback buffer
% describe Simple depth sort
% 3D BSP tree
% 2D BSP image tree for occlusion culling
% float vs. double
% polygon offsets
% PostScript shading
%
% From the GLpr FAQ:
%
% 3. Can GLpr handle 2D texture mapping?
%
% Only for pixel-based output (i.e., captured with glpImage()). GLpr
% cannot duplicate the effects of texture mapping for vector
% (move-draw) output. Unfortunately, the information required is not
% present in the OpenGL feedback buffer.
%
% 4. Can GLpr handle 1D texture mapping?
%
% Not in the present release. However, future releases may provide
% support for 1D texture maps (e.g.\ color lookup).
%
% Add references:
% - Fuchs, Kedem and Naylor for the BSP
% - Kilgard+OpenGL spec for the feedback buffer
\section{Contributors}
\label{sec:contrib}
\noemail{Michael Sweet}{[email protected]} for the original implementation of
the feedback buffer parser;
%
\noemail{Bruce Naylor}{[email protected]} for BSP tree and occlusion
culling hints;
%
\noemail{Marc Um{\'e}}{[email protected]} for the original list
code;
%
\noemail{Jean-Fran\c{c}ois Remacle}{[email protected]} for plane equation
fixes;
%
\noemail{Bart Kaptein}{[email protected]} for memory leak fixes;
%
\noemail{Quy Nguyen-Dai}{[email protected]} for output file size optimization;
%
\noemail{Sam Buss}{[email protected]} for the \dd{shfill}-based smooth shaded
triangle code;
%
\noemail{Shane Hill}{[email protected]} for the landscape option
implementation;
%
\noemail{Romain Boman}{[email protected]} for the Windows dll generation;
%
\noemail{Diego Santa Cruz}{[email protected]} for the new optimized
shaded triangle code and the \dd{shfill} management;
%
\noemail{Shahzad Muzaffar}{[email protected]} and \noemail{Lassi
Tuura}{[email protected]} for the new occlusion culling code, the
improvement of \dd{GL2PS_BEST_ROOT} and the imagemap support;
%
\noemail{Guy Barrand}{[email protected]} for his work on
\dd{gl2psDrawPixels} and the new viewport management;
%
\noemail{Rouben Rostamian}{[email protected]} and \noemail{Prabhu
Ramachandran}{[email protected]} for various bug reports and fixes;
%
\noemail{Micha Bieber}{[email protected]} for the PDF code;
%
\noemail{Olivier Couet}{[email protected]} for the initial SVG code;
%
\noemail{Fabian Wenzel}{[email protected]} for the PGF code and the
backend reorganization;
%
\noemail{Shai Ayal}{[email protected]} for rotated text support in
PostScript;
%
\noemail{Ian D. Gay}{[email protected]} for 64 bit arch patch;
%
\noemail{Cosmin Truta}{[email protected]} and \noemail{Baiju
Devani}{[email protected]} for various bug fixes and the new
\dd{gl2psSpecial} code;
%
\noemail{Alexander Danilov}{[email protected]} for a polygon offset bug
fix;
%
\noemail{Ben Fletcher}{[email protected]} for a
stippling pattern parser bug report;
%
\noemail{Jason Anderssen}{[email protected]} for memory leak fix
in pdf code;
%
\noemail{Sylvestre Ledru}{[email protected]} for SVG patches;
%
\noemail{Calixte Denizet}{[email protected]} for 64 bit patch;
%
\noemail{Ion Vasilief}{lion\[email protected]} and Paul Griffiths for
rotated text in PDF output;
%
\noemail{Ben Abbott}{[email protected]} for text alignment in SVG;
%
\noemail{David Lonie}{[email protected]} for VTK patches;
%
\noemail{Pantxo Diribarne}{[email protected]} for polygon offset
improvement, image scaling fix for SVG and PDF output, PostScript viewport color
bug fix, \dd{gl2psLineCap}, \dd{gl2psLineJoin} and \dd{gl2psSorting};
%
\noemail{David Lonie}{[email protected]} for direct addition of promitives
(for newer OpenGL APIs without feedback buffer);
%
\noemail{Dan Lipsa}{[email protected]} for bug fixes in PDF output.
\section{Links}
\label{sec:links}
\dd{GL2PS} was inspired by Mark Kilgard's original ``rendereps'' tutorial
(\url{http://www.opengl.org/resources/code/samples/mjktips/Feedback.html})
and Michael Sweet's GLP library (\url{http://www.easysw.com/~mike/opengl/}).
The (commercial) GLpr library from CEI (\url{http://www.ceintl.com/}) used
to provide functionality similar to GL2PS but does not seem to be available
anymore.
%\noemail{Toby White}{[email protected]} maintains a Python wrapper for
%\dd{GL2PS}, available at \url{http://tow.freeshell.org/software.html}.
\section{Versions}
\begin{description}
\item[0.1] (Feb 12, 2000) First distributed version.
\item[0.2] (Feb 20, 2000) Added \dd{GL2PS_POLYGON_BOUNDARY} and
\dd{GL2PS_BEST_ROOT}. API change: changed arguments of \dd{gl2psBeginPage}
and \dd{gl2psText}. Corrected some memory allocation stuff. First version
of this user's guide.
\item[0.21] (Mar 16, 2000) Initialization fixes.
\item[0.3] (Jul 29, 2000) Code cleanup. Added \dd{GL2PS_LINE_STIPPLE}.
\item[0.31] (Aug 14, 2000) Better handling of erroneous primitives.
\item[0.32] (May 23, 2001) Fixed memory leaks.
\item[0.4] (Jun 12, 2001) Added \dd{gl2psPointSize} and
\dd{gl2psLineWidth}. Some code cleanup to allow easier generation of
vector file formats other than postscript.