Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 2011-07-13 |
2 | // Created by: Sergey ZERCHANINOV | |
3 | // Copyright (c) 2011-2012 OPEN CASCADE SAS | |
4 | // | |
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. | |
9 | // | |
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. | |
12 | // | |
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. | |
19 | ||
5f8b738e | 20 | #include <OpenGl_GlCore11.hxx> |
2166f0fa | 21 | #include <OpenGl_Text.hxx> |
2166f0fa SK |
22 | #include <OpenGl_AspectText.hxx> |
23 | #include <OpenGl_Structure.hxx> | |
bf75be98 | 24 | #include <OpenGl_Workspace.hxx> |
2166f0fa | 25 | |
5f8b738e | 26 | #include <GL/glu.h> // gluUnProject() |
27 | ||
2166f0fa SK |
28 | /*----------------------------------------------------------------------*/ |
29 | ||
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) | |
35 | : myString(NULL) | |
36 | { | |
37 | const Techar *str = (const Techar *) AText.ToExtString(); | |
38 | ||
39 | //szv: instead of strlen + 1 | |
40 | int i = 0; while (str[i++]); | |
41 | ||
42 | wchar_t *wstr = new wchar_t[i]; | |
43 | ||
44 | //szv: instead of memcpy | |
45 | i = 0; while (wstr[i++] = (wchar_t)(*str++)); | |
46 | if (myString) delete[] myString; | |
47 | myString = wstr; | |
48 | ||
b8ddfc2f | 49 | myAttachPnt.xyz[0] = APoint.X(); |
50 | myAttachPnt.xyz[1] = APoint.Y(); | |
51 | myAttachPnt.xyz[2] = APoint.Z(); | |
2166f0fa SK |
52 | |
53 | myParam.Height = int (AHeight); | |
54 | ||
55 | myParam.HAlign = AHta; | |
56 | myParam.VAlign = AVta; | |
57 | } | |
58 | ||
59 | /*----------------------------------------------------------------------*/ | |
60 | ||
61 | OpenGl_Text::~OpenGl_Text () | |
62 | { | |
63 | if (myString) | |
64 | delete[] myString; | |
65 | } | |
66 | ||
67 | /*----------------------------------------------------------------------*/ | |
68 | ||
69 | void OpenGl_Text::Render (const Handle(OpenGl_Workspace) &AWorkspace) const | |
70 | { | |
71 | if ( AWorkspace->DegenerateModel > 0 && AWorkspace->SkipRatio >= 1.f ) | |
72 | return; | |
73 | ||
74 | const OpenGl_AspectText *aspect_text = AWorkspace->AspectText( Standard_True ); | |
75 | ||
76 | const TEL_COLOUR *tcolor, *scolor; | |
77 | ||
78 | // Use highlight colours | |
79 | if( AWorkspace->NamedStatus & OPENGL_NS_HIGHLIGHT ) | |
bf75be98 | 80 | { |
2166f0fa SK |
81 | tcolor = scolor = AWorkspace->HighlightColor; |
82 | } | |
83 | else | |
84 | { | |
85 | tcolor = &aspect_text->Color(); | |
86 | scolor = &aspect_text->SubtitleColor(); | |
87 | } | |
88 | ||
89 | // Handle annotation style | |
90 | GLboolean flag_zbuffer = GL_FALSE; | |
91 | if (aspect_text->StyleType() == Aspect_TOST_ANNOTATION) | |
92 | { | |
93 | flag_zbuffer = glIsEnabled(GL_DEPTH_TEST); | |
94 | if (flag_zbuffer) glDisable(GL_DEPTH_TEST); | |
95 | } | |
96 | ||
97 | AWorkspace->SetTextParam(&myParam); | |
98 | ||
2166f0fa SK |
99 | GLdouble modelMatrix[16], projMatrix[16]; |
100 | GLint viewport[4]; | |
101 | GLdouble objrefX, objrefY, objrefZ; | |
102 | GLdouble objX, objY, objZ; | |
103 | GLdouble obj1X, obj1Y, obj1Z; | |
104 | GLdouble obj2X, obj2Y, obj2Z; | |
105 | GLdouble obj3X, obj3Y, obj3Z; | |
106 | GLdouble winx1, winy1, winz1; | |
107 | GLdouble winx, winy, winz; | |
108 | GLint status; | |
109 | ||
110 | /* display type of text */ | |
111 | if (aspect_text->DisplayType() != Aspect_TODT_NORMAL) | |
112 | { | |
113 | /* Optimisation: il faudrait ne faire le Get qu'une fois par Redraw */ | |
114 | glGetIntegerv (GL_VIEWPORT, viewport); | |
115 | glGetDoublev (GL_MODELVIEW_MATRIX, modelMatrix); | |
116 | glGetDoublev (GL_PROJECTION_MATRIX, projMatrix); | |
117 | ||
118 | switch (aspect_text->DisplayType()) | |
119 | { | |
120 | case Aspect_TODT_BLEND: | |
2166f0fa SK |
121 | glEnable(GL_COLOR_LOGIC_OP); |
122 | glLogicOp(GL_XOR); | |
123 | break; | |
124 | case Aspect_TODT_SUBTITLE: | |
125 | { | |
126 | int sWidth, sAscent, sDescent; | |
127 | AWorkspace->StringSize(myString, sWidth, sAscent, sDescent); | |
128 | ||
bf75be98 | 129 | objrefX = (float)myAttachPnt.xyz[0]; |
130 | objrefY = (float)myAttachPnt.xyz[1]; | |
2166f0fa SK |
131 | objrefZ = (float)myAttachPnt.xyz[2]; |
132 | status = gluProject (objrefX, objrefY, objrefZ, modelMatrix, projMatrix, viewport, | |
133 | &winx1, &winy1, &winz1); | |
134 | ||
135 | winx = winx1; | |
136 | winy = winy1-sDescent; | |
bf75be98 | 137 | winz = winz1+0.00001; |
2166f0fa SK |
138 | status = gluUnProject (winx, winy, winz, modelMatrix, projMatrix, viewport, |
139 | &objX, &objY, &objZ); | |
140 | ||
141 | winx = winx1 + sWidth; | |
142 | winy = winy1-sDescent; | |
bf75be98 | 143 | winz = winz1+0.00001; /* il vaut mieux F+B / 1000000 ? */ |
2166f0fa SK |
144 | status = gluUnProject (winx, winy, winz, modelMatrix, projMatrix, viewport, |
145 | &obj1X, &obj1Y, &obj1Z); | |
146 | ||
147 | winx = winx1 + sWidth; | |
148 | winy = winy1 + sAscent; | |
bf75be98 | 149 | winz = winz1+0.00001; |
2166f0fa SK |
150 | status = gluUnProject (winx, winy, winz, modelMatrix, projMatrix, viewport, |
151 | &obj2X, &obj2Y, &obj2Z); | |
152 | ||
153 | winx = winx1; | |
154 | winy = winy1+ sAscent; | |
bf75be98 | 155 | winz = winz1+0.00001; |
2166f0fa SK |
156 | status = gluUnProject (winx, winy, winz, modelMatrix, projMatrix, viewport, |
157 | &obj3X, &obj3Y, &obj3Z); | |
158 | ||
159 | glColor3fv( scolor->rgb ); | |
160 | glBegin(GL_POLYGON); | |
161 | glVertex3d(objX, objY, objZ); | |
162 | glVertex3d(obj1X, obj1Y, obj1Z); | |
163 | glVertex3d(obj2X, obj2Y, obj2Z); | |
164 | glVertex3d(obj3X, obj3Y, obj3Z); | |
165 | glEnd(); | |
166 | break; | |
167 | } | |
168 | ||
169 | case Aspect_TODT_DEKALE: | |
bf75be98 | 170 | objrefX = (float)myAttachPnt.xyz[0]; |
171 | objrefY = (float)myAttachPnt.xyz[1]; | |
2166f0fa SK |
172 | objrefZ = (float)myAttachPnt.xyz[2]; |
173 | status = gluProject (objrefX, objrefY, objrefZ, modelMatrix, projMatrix, viewport, | |
174 | &winx1, &winy1, &winz1); | |
175 | ||
176 | winx = winx1+1; | |
177 | winy = winy1+1; | |
bf75be98 | 178 | winz = winz1+0.00001; |
2166f0fa SK |
179 | status = gluUnProject (winx, winy, winz, modelMatrix, projMatrix, viewport, |
180 | &objX, &objY, &objZ); | |
181 | ||
182 | glColor3fv( scolor->rgb ); | |
183 | AWorkspace->RenderText( myString, 0, (float)objX, (float)objY,(float)objZ ); | |
184 | winx = winx1-1; | |
185 | winy = winy1-1; | |
186 | status = gluUnProject (winx, winy, winz, modelMatrix, projMatrix, viewport, | |
187 | &objX, &objY, &objZ); | |
188 | ||
189 | AWorkspace->RenderText( myString, 0, (float)objX, (float)objY,(float)objZ ); | |
190 | winx = winx1-1; | |
191 | winy = winy1+1; | |
192 | status = gluUnProject (winx, winy, winz, modelMatrix, projMatrix, viewport, | |
bf75be98 | 193 | &objX, &objY, &objZ); |
2166f0fa SK |
194 | |
195 | AWorkspace->RenderText( myString, 0, (float)objX, (float)objY,(float)objZ ); | |
196 | winx = winx1+1; | |
197 | winy = winy1-1; | |
198 | status = gluUnProject (winx, winy, winz, modelMatrix, projMatrix, viewport, | |
199 | &objX, &objY, &objZ); | |
200 | AWorkspace->RenderText( myString, 0, (float)objX, (float)objY,(float)objZ ); | |
201 | break; | |
202 | } | |
203 | } | |
204 | ||
205 | glColor3fv( tcolor->rgb ); | |
206 | AWorkspace->RenderText( myString, 0, (float)myAttachPnt.xyz[0], (float)myAttachPnt.xyz[1],(float)myAttachPnt.xyz[2] ); | |
207 | /* maj attributs */ | |
208 | if (flag_zbuffer) glEnable(GL_DEPTH_TEST); | |
209 | if (aspect_text->DisplayType() == Aspect_TODT_BLEND) | |
210 | { | |
2166f0fa SK |
211 | glDisable(GL_COLOR_LOGIC_OP); |
212 | } | |
213 | } | |
214 | ||
5e27df78 | 215 | void OpenGl_Text::Release (const Handle(OpenGl_Context)& theContext) |
216 | { | |
217 | // | |
218 | } |