0022752: Fix compilation on Unix with FreeImage and GL2PS support
[occt.git] / src / OpenGl / OpenGl_GraphicDriver_Export.cxx
CommitLineData
b311480e 1// Copyright (c) 1999-2012 OPEN CASCADE SAS
2//
3// The content of this file is subject to the Open CASCADE Technology Public
4// License Version 6.5 (the "License"). You may not use the content of this file
5// except in compliance with the License. Please obtain a copy of the License
6// at http://www.opencascade.org and read it completely before using this file.
7//
8// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
10//
11// The Original Code and all software distributed under the License is
12// distributed on an "AS IS" basis, without warranty of any kind, and the
13// Initial Developer hereby disclaims all such warranties, including without
14// limitation, any warranties of merchantability, fitness for a particular
15// purpose or non-infringement. Please see the License for the specific terms
16// and conditions governing the rights and limitations under the License.
17
7fd59977 18/************************************************************************/
19/* Includes */
20/************************************************************************/
21
2166f0fa 22#include <OpenGl_GraphicDriver.hxx>
7fd59977 23#include <OSD_Localizer.hxx>
24
498ce577 25#ifdef HAVE_CONFIG_H
26# include <config.h>
27#endif
28
7fd59977 29#ifdef HAVE_GL2PS
30#include <gl2ps.h>
31#endif
32
33#include <locale.h>
34
7fd59977 35/************************************************************************/
36/* Print Methods */
37/************************************************************************/
38
5cedc27f
K
39Standard_Boolean OpenGl_GraphicDriver::Export (const Standard_CString theFileName,
40 const Graphic3d_ExportFormat theFormat,
41 const Graphic3d_SortType theSortType,
42 const Standard_Integer theWidth,
43 const Standard_Integer theHeight,
44 const Graphic3d_CView& theView,
45 const Aspect_CLayer2d& theLayerUnder,
46 const Aspect_CLayer2d& theLayerOver,
47 const Standard_Real /*thePrecision*/,
48 const Standard_Address /*theProgressBarFunc*/,
49 const Standard_Address /*theProgressObject*/)
7fd59977 50{
51#ifdef HAVE_GL2PS
5cedc27f
K
52 Standard_Integer aFormat = -1;
53 Standard_Integer aSortType = Graphic3d_ST_BSP_Tree;
54 switch (theFormat)
7fd59977 55 {
5cedc27f
K
56 case Graphic3d_EF_PostScript:
57 aFormat = GL2PS_PS;
58 break;
59 case Graphic3d_EF_EnhPostScript:
60 aFormat = GL2PS_EPS;
61 break;
62 case Graphic3d_EF_TEX:
63 aFormat = GL2PS_TEX;
64 break;
65 case Graphic3d_EF_PDF:
66 aFormat = GL2PS_PDF;
67 break;
68 case Graphic3d_EF_SVG:
69 aFormat = GL2PS_SVG;
70 break;
71 case Graphic3d_EF_PGF:
72 aFormat = GL2PS_PGF;
73 break;
74 case Graphic3d_EF_EMF:
75 //aFormat = GL2PS_EMF;
76 aFormat = GL2PS_PGF + 1; // 6
77 break;
78 default:
79 // unsupported format
80 return Standard_False;
7fd59977 81 }
82
5cedc27f 83 switch (theSortType)
7fd59977 84 {
5cedc27f
K
85 case Graphic3d_ST_Simple:
86 aSortType = GL2PS_SIMPLE_SORT;
87 break;
88 case Graphic3d_ST_BSP_Tree:
89 aSortType = GL2PS_BSP_SORT;
90 break;
91 }
92
93 GLint aViewport[4];
94 aViewport[0] = 0;
95 aViewport[1] = 0;
96 aViewport[2] = theWidth;
97 aViewport[3] = theHeight;
7fd59977 98
5cedc27f
K
99 GLint aBufferSize = 1024 * 1024;
100 GLint anErrCode = GL2PS_SUCCESS;
7fd59977 101
5cedc27f
K
102 // gl2ps uses standard write functions and do not check locale
103 OSD_Localizer locate (LC_NUMERIC, "C");
7fd59977 104
5cedc27f 105 while (aBufferSize > 0)
7fd59977 106 {
5cedc27f
K
107 // current patch for EMF support in gl2ps uses WinAPI functions to create file
108 FILE* aFileH = (theFormat != Graphic3d_EF_EMF) ? fopen (theFileName, "wb") : NULL;
109 anErrCode = gl2psBeginPage ("", "", aViewport, aFormat, aSortType,
7fd59977 110 GL2PS_DRAW_BACKGROUND | GL2PS_OCCLUSION_CULL | GL2PS_BEST_ROOT/* | GL2PS_SIMPLE_LINE_OFFSET*/,
111 GL_RGBA, 0, NULL,
5cedc27f
K
112 0, 0, 0, aBufferSize, aFileH, theFileName);
113 if (anErrCode != GL2PS_SUCCESS)
114 {
115 // initialization failed
116 if (aFileH != NULL)
117 fclose (aFileH);
118 break;
119 }
120 Redraw (theView, theLayerUnder, theLayerOver);
121
122 anErrCode = gl2psEndPage();
123 if (aFileH != NULL)
124 fclose (aFileH);
125
126 if (anErrCode == GL2PS_OVERFLOW)
127 aBufferSize *= 2;
128 else
129 break;
7fd59977 130 }
131
132 locate.Restore();
5cedc27f
K
133 return anErrCode == GL2PS_SUCCESS;
134#else
135 return Standard_False;
7fd59977 136#endif
7fd59977 137}