0026122: Visualization, TKOpenGl - clipping and capping is broken when ffp is disable...
[occt.git] / src / OpenGl / OpenGl_PrinterContext.cxx
1 // Created on: 2011-05-20
2 // Created by: Anton POLETAEV
3 // Copyright (c) 2011-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #include <OpenGl_GlCore11.hxx>
17 #include <OpenGl_PrinterContext.hxx>
18
19
20 //=======================================================================
21 //function : OpenGl_PrinterContext
22 //purpose  :
23 //=======================================================================
24 OpenGl_PrinterContext::OpenGl_PrinterContext()
25 : myProjTransform  (0, 3, 0, 3),
26   myScaleX (1.0f),
27   myScaleY (1.0f),
28   myLayerViewportX (0),
29   myLayerViewportY (0)
30
31 {
32   // identity projection matrix
33   Standard_Real anInitValue = 0.0;
34   myProjTransform.Init (anInitValue);
35   myProjTransform (0, 0)  = 1.0;
36   myProjTransform (1, 1)  = 1.0;
37   myProjTransform (2, 2)  = 1.0;
38   myProjTransform (3, 3)  = 1.0;
39   SetProjTransformation (myProjTransform);
40 }
41
42 // =======================================================================
43 // function : ~OpenGl_PrinterContext
44 // purpose  :
45 // =======================================================================
46 OpenGl_PrinterContext::~OpenGl_PrinterContext()
47 {
48   //
49 }
50
51 // =======================================================================
52 // function : ProjTransformation
53 // purpose  :
54 // =======================================================================
55 OpenGl_Mat4 OpenGl_PrinterContext::ProjTransformation()
56 {
57   return OpenGl_Mat4::Map (myProjMatrixGl);
58 }
59
60 // =======================================================================
61 // function : SetProjTransformation
62 // purpose  : Set view projection transformation matrix for printing purposes.
63 //            theProjTransform parameter should be an 4x4 array.
64 // =======================================================================
65 bool OpenGl_PrinterContext::SetProjTransformation (const TColStd_Array2OfReal& thePrj)
66 {
67   if (thePrj.RowLength () != 4 || thePrj.ColLength () != 4)
68   {
69     return false;
70   }
71
72   myProjTransform = thePrj;
73   for (int i = 0, k = 0; i < 4; i++)
74   {
75     for (int j = 0; j < 4; j++, k++)
76     {
77       myProjMatrixGl[k] = (Standard_ShortReal )myProjTransform (i, j);
78     }
79   }
80   return true;
81 }
82
83 // =======================================================================
84 // function : SetScale
85 // purpose  :
86 // =======================================================================
87 void OpenGl_PrinterContext::SetScale (const Standard_ShortReal theScaleX,
88                                       const Standard_ShortReal theScaleY)
89 {
90   myScaleX = theScaleX;
91   myScaleY = theScaleY;
92 }
93
94 // =======================================================================
95 // function : SetLayerViewport
96 // purpose  :
97 // =======================================================================
98 void OpenGl_PrinterContext::SetLayerViewport (const Standard_Integer theViewportX,
99                                               const Standard_Integer theViewportY)
100 {
101   myLayerViewportX = theViewportX;
102   myLayerViewportY = theViewportY;
103 }