0f57d20b63373175f56554b7bf08a2172abe51d5
[occt.git] / src / OpenGl / OpenGl_GraphicDriver_Export.cxx
1 /************************************************************************/
2 /* Includes                                                             */
3 /************************************************************************/
4
5 #include <OpenGl_GraphicDriver.jxx>
6 #include <OSD_Localizer.hxx>
7
8 #ifdef HAVE_GL2PS
9 #include <gl2ps.h>
10 #endif
11
12 #include <locale.h>
13
14
15
16 /************************************************************************/
17 /* Print Methods                                                        */
18 /************************************************************************/
19
20 void OpenGl_GraphicDriver::Export( const Standard_CString FileName,
21                                    const Graphic3d_ExportFormat Format,
22                                    const Graphic3d_SortType aSortType,
23                                    const Standard_Integer W,
24                                    const Standard_Integer H,
25                                    const Graphic3d_CView& View,
26                                    const Aspect_CLayer2d& Under,
27                                    const Aspect_CLayer2d& Over,
28                                    const Standard_Real Precision,
29                                    const Standard_Address ProgressBarFunc,
30                                    const Standard_Address ProgressObject )
31 {
32 #ifdef HAVE_GL2PS
33
34   OSD_Localizer locate(LC_NUMERIC,"C");
35  
36   Standard_Integer mode = -1;
37   Standard_Integer sortType = Graphic3d_ST_BSP_Tree;
38   switch( Format )
39   {
40   case Graphic3d_EF_PostScript:
41     mode = GL2PS_PS;
42     break;
43   case Graphic3d_EF_EnhPostScript:
44     mode = GL2PS_EPS;
45     break;
46   case Graphic3d_EF_TEX:
47     mode = GL2PS_TEX;
48     break;
49   case Graphic3d_EF_PDF:
50     mode = GL2PS_PDF;
51     break;  
52   case Graphic3d_EF_SVG:
53     mode = GL2PS_SVG;
54     break;
55   case Graphic3d_EF_PGF:
56     mode = GL2PS_PGF;
57     break;
58   }
59
60   switch( aSortType )
61   {
62   case Graphic3d_ST_Simple:
63     sortType = GL2PS_SIMPLE_SORT;
64     break;
65   case Graphic3d_ST_BSP_Tree:
66     sortType = GL2PS_BSP_SORT;
67     break;
68   }     
69
70   GLint viewport[4];
71   viewport[0] = 0;
72   viewport[1] = 0;
73   viewport[2] = W;
74   viewport[3] = H;
75
76   GLint buffersize = 1024*1024;   
77
78   while( buffersize>0 )
79   {
80     FILE *file = fopen(FileName,"wb");
81     gl2psBeginPage( "", "", viewport, mode, sortType,
82                     GL2PS_DRAW_BACKGROUND | GL2PS_OCCLUSION_CULL | GL2PS_BEST_ROOT/* | GL2PS_SIMPLE_LINE_OFFSET*/,
83                     GL_RGBA, 0, NULL,
84                     0, 0, 0, buffersize, file, FileName);
85
86     Redraw( View, Under, Over );
87
88     GLint num = gl2psEndPage();
89
90     fclose(file);
91
92     if( num==GL2PS_OVERFLOW )
93        buffersize *= 2;
94      else
95        break;
96   }
97
98   locate.Restore();
99
100 #endif
101
102 }