1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include "ogl_canvastools.hxx"
12 #include <canvas/debug.hxx>
13 #include <tools/diagnose_ex.h>
14 #include <basegfx/tools/canvastools.hxx>
15 #include <basegfx/matrix/b2dhommatrix.hxx>
16 #include <basegfx/tools/tools.hxx>
17 #include <basegfx/polygon/b2dpolypolygon.hxx>
18 #include <basegfx/polygon/b2dpolygontriangulator.hxx>
19 #include <basegfx/polygon/b2dpolypolygontools.hxx>
21 #include <com/sun/star/rendering/ARGBColor.hpp>
25 using namespace ::com::sun::star
;
29 /// triangulates polygon before
30 void renderComplexPolyPolygon( const ::basegfx::B2DPolyPolygon
& rPolyPoly
)
32 ::basegfx::B2DPolyPolygon
aPolyPoly(rPolyPoly
);
33 if( aPolyPoly
.areControlPointsUsed() )
34 aPolyPoly
= rPolyPoly
.getDefaultAdaptiveSubdivision();
35 const ::basegfx::B2DRange
& rBounds(aPolyPoly
.getB2DRange());
36 const double nWidth
=rBounds
.getWidth();
37 const double nHeight
=rBounds
.getHeight();
38 const ::basegfx::B2DPolygon
& rTriangulatedPolygon(
39 ::basegfx::triangulator::triangulate(aPolyPoly
));
41 for( sal_uInt32 i
=0; i
<rTriangulatedPolygon
.count(); i
++ )
43 const ::basegfx::B2DPoint
& rPt( rTriangulatedPolygon
.getB2DPoint(i
) );
44 const double s(rPt
.getX()/nWidth
);
45 const double t(rPt
.getY()/nHeight
);
46 glTexCoord2f(s
,t
); glVertex2d(rPt
.getX(), rPt
.getY());
50 /** only use this for line polygons.
52 better not leave triangulation to OpenGL. also, ignores texturing
54 void renderPolyPolygon( const ::basegfx::B2DPolyPolygon
& rPolyPoly
)
56 ::basegfx::B2DPolyPolygon
aPolyPoly(rPolyPoly
);
57 if( aPolyPoly
.areControlPointsUsed() )
58 aPolyPoly
= rPolyPoly
.getDefaultAdaptiveSubdivision();
60 for( sal_uInt32 i
=0; i
<aPolyPoly
.count(); i
++ )
62 glBegin(GL_LINE_STRIP
);
64 const ::basegfx::B2DPolygon
& rPolygon( aPolyPoly
.getB2DPolygon(i
) );
66 const sal_uInt32 nPts
=rPolygon
.count();
67 const sal_uInt32 nExtPts
=nPts
+ int(rPolygon
.isClosed());
68 for( sal_uInt32 j
=0; j
<nExtPts
; j
++ )
70 const ::basegfx::B2DPoint
& rPt( rPolygon
.getB2DPoint( j
% nPts
) );
71 glVertex2d(rPt
.getX(), rPt
.getY());
78 void setupState( const ::basegfx::B2DHomMatrix
& rTransform
,
81 const rendering::ARGBColor
& rColor
)
83 double aGLTransform
[] =
85 rTransform
.get(0,0), rTransform
.get(1,0), 0, 0,
86 rTransform
.get(0,1), rTransform
.get(1,1), 0, 0,
88 rTransform
.get(0,2), rTransform
.get(1,2), 0, 1
90 glMultMatrixd(aGLTransform
);
93 glBlendFunc(eSrcBlend
, eDstBlend
);
101 // glBlendEquation( GLenum mode );
102 // glBlendColor( GLclampf red, GLclampf green,GLclampf blue, GLclampf alpha );
103 // glConvolutionFilter1D
104 // glConvolutionFilter2D
105 // glSeparableFilter2D
108 void renderOSD( const std::vector
<double>& rNumbers
, double scale
)
111 basegfx::B2DHomMatrix aTmp
;
112 basegfx::B2DHomMatrix aScaleShear
;
113 aScaleShear
.shearX(-0.1);
114 aScaleShear
.scale(scale
,scale
);
116 for( size_t i
=0; i
<rNumbers
.size(); ++i
)
122 basegfx::B2DPolyPolygon aPoly
=
123 basegfx::tools::number2PolyPolygon(rNumbers
[i
],10,3);
125 aTmp
=aTmp
*aScaleShear
;
126 aPoly
.transform(aTmp
);
129 renderPolyPolygon(aPoly
);
134 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */