1 // Created on: 2011-07-13
2 // Created by: Sergey ZERCHANINOV
3 // Copyright (c) 2011-2012 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
21 #include <OpenGl_GlCore11.hxx>
22 #include <OpenGl_Text.hxx>
23 #include <OpenGl_AspectText.hxx>
24 #include <OpenGl_Structure.hxx>
26 #include <GL/glu.h> // gluUnProject()
28 /*----------------------------------------------------------------------*/
30 OpenGl_Text::OpenGl_Text (const TCollection_ExtendedString& AText,
31 const Graphic3d_Vertex& APoint,
32 const Standard_Real AHeight,
33 const Graphic3d_HorizontalTextAlignment AHta,
34 const Graphic3d_VerticalTextAlignment AVta)
37 const Techar *str = (const Techar *) AText.ToExtString();
39 //szv: instead of strlen + 1
40 int i = 0; while (str[i++]);
42 wchar_t *wstr = new wchar_t[i];
44 //szv: instead of memcpy
45 i = 0; while (wstr[i++] = (wchar_t)(*str++));
46 if (myString) delete[] myString;
49 Standard_Real X, Y, Z;
50 APoint.Coord(X, Y, Z);
51 myAttachPnt.xyz[0] = float (X);
52 myAttachPnt.xyz[1] = float (Y);
53 myAttachPnt.xyz[2] = float (Z);
55 myParam.Height = int (AHeight);
57 myParam.HAlign = AHta;
58 myParam.VAlign = AVta;
61 /*----------------------------------------------------------------------*/
63 OpenGl_Text::~OpenGl_Text ()
69 /*----------------------------------------------------------------------*/
71 void OpenGl_Text::Render (const Handle(OpenGl_Workspace) &AWorkspace) const
73 if ( AWorkspace->DegenerateModel > 0 && AWorkspace->SkipRatio >= 1.f )
76 const OpenGl_AspectText *aspect_text = AWorkspace->AspectText( Standard_True );
78 const TEL_COLOUR *tcolor, *scolor;
80 // Use highlight colours
81 if( AWorkspace->NamedStatus & OPENGL_NS_HIGHLIGHT )
83 tcolor = scolor = AWorkspace->HighlightColor;
87 tcolor = &aspect_text->Color();
88 scolor = &aspect_text->SubtitleColor();
91 // Handle annotation style
92 GLboolean flag_zbuffer = GL_FALSE;
93 if (aspect_text->StyleType() == Aspect_TOST_ANNOTATION)
95 flag_zbuffer = glIsEnabled(GL_DEPTH_TEST);
96 if (flag_zbuffer) glDisable(GL_DEPTH_TEST);
99 AWorkspace->SetTextParam(&myParam);
101 GLdouble modelMatrix[16], projMatrix[16];
103 GLdouble objrefX, objrefY, objrefZ;
104 GLdouble objX, objY, objZ;
105 GLdouble obj1X, obj1Y, obj1Z;
106 GLdouble obj2X, obj2Y, obj2Z;
107 GLdouble obj3X, obj3Y, obj3Z;
108 GLdouble winx1, winy1, winz1;
109 GLdouble winx, winy, winz;
112 /* display type of text */
113 if (aspect_text->DisplayType() != Aspect_TODT_NORMAL)
115 /* Optimisation: il faudrait ne faire le Get qu'une fois par Redraw */
116 glGetIntegerv (GL_VIEWPORT, viewport);
117 glGetDoublev (GL_MODELVIEW_MATRIX, modelMatrix);
118 glGetDoublev (GL_PROJECTION_MATRIX, projMatrix);
120 switch (aspect_text->DisplayType())
122 case Aspect_TODT_BLEND:
123 glEnable(GL_COLOR_LOGIC_OP);
126 case Aspect_TODT_SUBTITLE:
128 int sWidth, sAscent, sDescent;
129 AWorkspace->StringSize(myString, sWidth, sAscent, sDescent);
131 objrefX = (float)myAttachPnt.xyz[0];
132 objrefY = (float)myAttachPnt.xyz[1];
133 objrefZ = (float)myAttachPnt.xyz[2];
134 status = gluProject (objrefX, objrefY, objrefZ, modelMatrix, projMatrix, viewport,
135 &winx1, &winy1, &winz1);
138 winy = winy1-sDescent;
139 winz = winz1+0.00001;
140 status = gluUnProject (winx, winy, winz, modelMatrix, projMatrix, viewport,
141 &objX, &objY, &objZ);
143 winx = winx1 + sWidth;
144 winy = winy1-sDescent;
145 winz = winz1+0.00001; /* il vaut mieux F+B / 1000000 ? */
146 status = gluUnProject (winx, winy, winz, modelMatrix, projMatrix, viewport,
147 &obj1X, &obj1Y, &obj1Z);
149 winx = winx1 + sWidth;
150 winy = winy1 + sAscent;
151 winz = winz1+0.00001;
152 status = gluUnProject (winx, winy, winz, modelMatrix, projMatrix, viewport,
153 &obj2X, &obj2Y, &obj2Z);
156 winy = winy1+ sAscent;
157 winz = winz1+0.00001;
158 status = gluUnProject (winx, winy, winz, modelMatrix, projMatrix, viewport,
159 &obj3X, &obj3Y, &obj3Z);
161 glColor3fv( scolor->rgb );
163 glVertex3d(objX, objY, objZ);
164 glVertex3d(obj1X, obj1Y, obj1Z);
165 glVertex3d(obj2X, obj2Y, obj2Z);
166 glVertex3d(obj3X, obj3Y, obj3Z);
171 case Aspect_TODT_DEKALE:
172 objrefX = (float)myAttachPnt.xyz[0];
173 objrefY = (float)myAttachPnt.xyz[1];
174 objrefZ = (float)myAttachPnt.xyz[2];
175 status = gluProject (objrefX, objrefY, objrefZ, modelMatrix, projMatrix, viewport,
176 &winx1, &winy1, &winz1);
180 winz = winz1+0.00001;
181 status = gluUnProject (winx, winy, winz, modelMatrix, projMatrix, viewport,
182 &objX, &objY, &objZ);
184 glColor3fv( scolor->rgb );
185 AWorkspace->RenderText( myString, 0, (float)objX, (float)objY,(float)objZ );
188 status = gluUnProject (winx, winy, winz, modelMatrix, projMatrix, viewport,
189 &objX, &objY, &objZ);
191 AWorkspace->RenderText( myString, 0, (float)objX, (float)objY,(float)objZ );
194 status = gluUnProject (winx, winy, winz, modelMatrix, projMatrix, viewport,
195 &objX, &objY, &objZ);
197 AWorkspace->RenderText( myString, 0, (float)objX, (float)objY,(float)objZ );
200 status = gluUnProject (winx, winy, winz, modelMatrix, projMatrix, viewport,
201 &objX, &objY, &objZ);
202 AWorkspace->RenderText( myString, 0, (float)objX, (float)objY,(float)objZ );
207 glColor3fv( tcolor->rgb );
208 AWorkspace->RenderText( myString, 0, (float)myAttachPnt.xyz[0], (float)myAttachPnt.xyz[1],(float)myAttachPnt.xyz[2] );
210 if (flag_zbuffer) glEnable(GL_DEPTH_TEST);
211 if (aspect_text->DisplayType() == Aspect_TODT_BLEND)
213 glDisable(GL_COLOR_LOGIC_OP);
217 void OpenGl_Text::Release (const Handle(OpenGl_Context)& theContext)