1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
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.
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.
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.
18 #include <OpenGl_GraphicDriver.hxx>
19 #include <OpenGl_Context.hxx>
20 #include <OpenGl_CView.hxx>
22 #include <Standard_CLocaleSentry.hxx>
32 /************************************************************************/
34 /************************************************************************/
36 Standard_Boolean OpenGl_GraphicDriver::Export (const Standard_CString theFileName,
37 const Graphic3d_ExportFormat theFormat,
38 const Graphic3d_SortType theSortType,
39 const Standard_Integer theWidth,
40 const Standard_Integer theHeight,
41 const Graphic3d_CView& theView,
42 const Aspect_CLayer2d& theLayerUnder,
43 const Aspect_CLayer2d& theLayerOver,
44 const Standard_Real /*thePrecision*/,
45 const Standard_Address /*theProgressBarFunc*/,
46 const Standard_Address /*theProgressObject*/)
49 // gl2psBeginPage() will call OpenGL functions
50 // so we should activate correct GL context before redraw scene call
51 const OpenGl_CView* aCView = (const OpenGl_CView* )theView.ptrView;
52 if (aCView == NULL || !aCView->WS->GetGlContext()->MakeCurrent())
54 return Standard_False;
57 Standard_Integer aFormat = -1;
58 Standard_Integer aSortType = Graphic3d_ST_BSP_Tree;
61 case Graphic3d_EF_PostScript:
64 case Graphic3d_EF_EnhPostScript:
67 case Graphic3d_EF_TEX:
70 case Graphic3d_EF_PDF:
73 case Graphic3d_EF_SVG:
76 case Graphic3d_EF_PGF:
79 case Graphic3d_EF_EMF:
80 //aFormat = GL2PS_EMF;
81 aFormat = GL2PS_PGF + 1; // 6
85 return Standard_False;
90 case Graphic3d_ST_Simple:
91 aSortType = GL2PS_SIMPLE_SORT;
93 case Graphic3d_ST_BSP_Tree:
94 aSortType = GL2PS_BSP_SORT;
101 aViewport[2] = theWidth;
102 aViewport[3] = theHeight;
104 GLint aBufferSize = 1024 * 1024;
105 GLint anErrCode = GL2PS_SUCCESS;
107 // gl2ps uses standard write functions and do not check locale
108 Standard_CLocaleSentry aLocaleSentry;
110 while (aBufferSize > 0)
112 // current patch for EMF support in gl2ps uses WinAPI functions to create file
113 FILE* aFileH = (theFormat != Graphic3d_EF_EMF) ? fopen (theFileName, "wb") : NULL;
114 anErrCode = gl2psBeginPage ("", "", aViewport, aFormat, aSortType,
115 GL2PS_DRAW_BACKGROUND | GL2PS_OCCLUSION_CULL | GL2PS_BEST_ROOT/* | GL2PS_SIMPLE_LINE_OFFSET*/,
117 0, 0, 0, aBufferSize, aFileH, theFileName);
118 if (anErrCode != GL2PS_SUCCESS)
120 // initialization failed
125 Redraw (theView, theLayerUnder, theLayerOver);
127 anErrCode = gl2psEndPage();
131 if (anErrCode == GL2PS_OVERFLOW)
137 return anErrCode == GL2PS_SUCCESS;
139 return Standard_False;