Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : */
9 :
10 : #include "ogl_canvastools.hxx"
11 :
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>
20 :
21 : #include <com/sun/star/rendering/ARGBColor.hpp>
22 :
23 : #include <GL/glew.h>
24 :
25 : using namespace ::com::sun::star;
26 :
27 : namespace oglcanvas
28 : {
29 : /// triangulates polygon before
30 0 : void renderComplexPolyPolygon( const ::basegfx::B2DPolyPolygon& rPolyPoly )
31 : {
32 0 : ::basegfx::B2DPolyPolygon aPolyPoly(rPolyPoly);
33 0 : if( aPolyPoly.areControlPointsUsed() )
34 0 : aPolyPoly = rPolyPoly.getDefaultAdaptiveSubdivision();
35 0 : const ::basegfx::B2DRange& rBounds(aPolyPoly.getB2DRange());
36 0 : const double nWidth=rBounds.getWidth();
37 0 : const double nHeight=rBounds.getHeight();
38 : const ::basegfx::B2DPolygon& rTriangulatedPolygon(
39 0 : ::basegfx::triangulator::triangulate(aPolyPoly));
40 :
41 0 : for( sal_uInt32 i=0; i<rTriangulatedPolygon.count(); i++ )
42 : {
43 0 : const ::basegfx::B2DPoint& rPt( rTriangulatedPolygon.getB2DPoint(i) );
44 0 : const double s(rPt.getX()/nWidth);
45 0 : const double t(rPt.getY()/nHeight);
46 0 : glTexCoord2f(s,t); glVertex2d(rPt.getX(), rPt.getY());
47 0 : }
48 0 : }
49 :
50 : /** only use this for line polygons.
51 :
52 : better not leave triangulation to OpenGL. also, ignores texturing
53 : */
54 0 : void renderPolyPolygon( const ::basegfx::B2DPolyPolygon& rPolyPoly )
55 : {
56 0 : ::basegfx::B2DPolyPolygon aPolyPoly(rPolyPoly);
57 0 : if( aPolyPoly.areControlPointsUsed() )
58 0 : aPolyPoly = rPolyPoly.getDefaultAdaptiveSubdivision();
59 :
60 0 : for( sal_uInt32 i=0; i<aPolyPoly.count(); i++ )
61 : {
62 0 : glBegin(GL_LINE_STRIP);
63 :
64 0 : const ::basegfx::B2DPolygon& rPolygon( aPolyPoly.getB2DPolygon(i) );
65 :
66 0 : const sal_uInt32 nPts=rPolygon.count();
67 0 : const sal_uInt32 nExtPts=nPts + int(rPolygon.isClosed());
68 0 : for( sal_uInt32 j=0; j<nExtPts; j++ )
69 : {
70 0 : const ::basegfx::B2DPoint& rPt( rPolygon.getB2DPoint( j % nPts ) );
71 0 : glVertex2d(rPt.getX(), rPt.getY());
72 0 : }
73 :
74 0 : glEnd();
75 0 : }
76 0 : }
77 :
78 0 : void setupState( const ::basegfx::B2DHomMatrix& rTransform,
79 : GLenum eSrcBlend,
80 : GLenum eDstBlend,
81 : const rendering::ARGBColor& rColor )
82 : {
83 : double aGLTransform[] =
84 : {
85 0 : rTransform.get(0,0), rTransform.get(1,0), 0, 0,
86 0 : rTransform.get(0,1), rTransform.get(1,1), 0, 0,
87 : 0, 0, 1, 0,
88 0 : rTransform.get(0,2), rTransform.get(1,2), 0, 1
89 0 : };
90 0 : glMultMatrixd(aGLTransform);
91 :
92 0 : glEnable(GL_BLEND);
93 0 : glBlendFunc(eSrcBlend, eDstBlend);
94 :
95 : glColor4d(rColor.Red,
96 : rColor.Green,
97 : rColor.Blue,
98 0 : rColor.Alpha);
99 :
100 : // GL 1.2:
101 : // glBlendEquation( GLenum mode );
102 : // glBlendColor( GLclampf red, GLclampf green,GLclampf blue, GLclampf alpha );
103 : // glConvolutionFilter1D
104 : // glConvolutionFilter2D
105 : // glSeparableFilter2D
106 0 : }
107 :
108 0 : void renderOSD( const std::vector<double>& rNumbers, double scale )
109 : {
110 0 : double y=4.0;
111 0 : basegfx::B2DHomMatrix aTmp;
112 0 : basegfx::B2DHomMatrix aScaleShear;
113 0 : aScaleShear.shearX(-0.1);
114 0 : aScaleShear.scale(scale,scale);
115 :
116 0 : for( size_t i=0; i<rNumbers.size(); ++i )
117 : {
118 0 : aTmp.identity();
119 0 : aTmp.translate(0,y);
120 0 : y += 1.2*scale;
121 :
122 : basegfx::B2DPolyPolygon aPoly=
123 0 : basegfx::tools::number2PolyPolygon(rNumbers[i],10,3);
124 :
125 0 : aTmp=aTmp*aScaleShear;
126 0 : aPoly.transform(aTmp);
127 :
128 0 : glColor4f(0,1,0,1);
129 0 : renderPolyPolygon(aPoly);
130 0 : }
131 0 : }
132 : }
133 :
134 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|