Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 2011-07-13 |
2 | // Created by: Sergey ZERCHANINOV | |
a174a3c5 | 3 | // Copyright (c) 2011-2013 OPEN CASCADE SAS |
b311480e | 4 | // |
973c2be1 | 5 | // This file is part of Open CASCADE Technology software library. |
b311480e | 6 | // |
d5f74e42 | 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 | |
973c2be1 | 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. | |
b311480e | 12 | // |
973c2be1 | 13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. | |
b311480e | 15 | |
2166f0fa | 16 | #include <OpenGl_AspectText.hxx> |
30f0ad28 | 17 | #include <OpenGl_GlCore11.hxx> |
a174a3c5 | 18 | #include <OpenGl_GraphicDriver.hxx> |
30f0ad28 | 19 | #include <OpenGl_ShaderManager.hxx> |
20 | #include <OpenGl_ShaderProgram.hxx> | |
21 | #include <OpenGl_ShaderStates.hxx> | |
22 | #include <OpenGl_Text.hxx> | |
bf75be98 | 23 | #include <OpenGl_Workspace.hxx> |
ce01ec26 | 24 | #include <OpenGl_View.hxx> |
2166f0fa | 25 | |
a174a3c5 | 26 | #include <Font_FontMgr.hxx> |
d2eddacc | 27 | #include <Font_FTFont.hxx> |
825aa485 | 28 | #include <Graphic3d_TransformUtils.hxx> |
a174a3c5 | 29 | #include <TCollection_HAsciiString.hxx> |
30 | ||
a174a3c5 | 31 | #ifdef HAVE_GL2PS |
32 | #include <gl2ps.h> | |
33 | #endif | |
34 | ||
35 | namespace | |
2166f0fa | 36 | { |
c827ea3a | 37 | static const GLdouble THE_IDENTITY_MATRIX[16] = |
a174a3c5 | 38 | { |
c827ea3a | 39 | 1.0, 0.0, 0.0, 0.0, |
40 | 0.0, 1.0, 0.0, 0.0, | |
41 | 0.0, 0.0, 1.0, 0.0, | |
42 | 0.0, 0.0, 0.0, 1.0 | |
a174a3c5 | 43 | }; |
44 | ||
45 | #ifdef HAVE_GL2PS | |
46 | static char const* TheFamily[] = {"Helvetica", "Courier", "Times"}; | |
47 | static char const* TheItalic[] = {"Oblique", "Oblique", "Italic"}; | |
48 | static char const* TheBase[] = {"", "", "-Roman"}; | |
49 | ||
50 | //! Convert font name used for rendering to some "good" font names | |
51 | //! that produce good vector text. | |
52 | static void getGL2PSFontName (const char* theSrcFont, | |
53 | char* thePsFont) | |
54 | { | |
55 | if (strstr (theSrcFont, "Symbol")) | |
56 | { | |
57 | sprintf (thePsFont, "%s", "Symbol"); | |
58 | return; | |
59 | } | |
60 | else if (strstr (theSrcFont, "ZapfDingbats")) | |
61 | { | |
62 | sprintf (thePsFont, "%s", "WingDings"); | |
63 | return; | |
64 | } | |
2166f0fa | 65 | |
a174a3c5 | 66 | int aFontId = 0; |
67 | bool isBold = false; | |
68 | bool isItalic = false; | |
69 | if (strstr (theSrcFont, "Courier")) | |
70 | { | |
71 | aFontId = 1; | |
72 | } | |
73 | else if (strstr (theSrcFont, "Times")) | |
74 | { | |
75 | aFontId = 2; | |
76 | } | |
2166f0fa | 77 | |
a174a3c5 | 78 | if (strstr (theSrcFont, "Bold")) |
79 | { | |
80 | isBold = true; | |
81 | } | |
82 | if (strstr (theSrcFont, "Italic") | |
83 | || strstr (theSrcFont, "Oblique")) | |
84 | { | |
85 | isItalic = true; | |
86 | } | |
2166f0fa | 87 | |
a174a3c5 | 88 | if (isBold) |
89 | { | |
a174a3c5 | 90 | if (isItalic) |
91 | { | |
8b224a09 | 92 | sprintf (thePsFont, "%s-Bold%s", TheFamily[aFontId], TheItalic[aFontId]); |
93 | } | |
94 | else | |
95 | { | |
96 | sprintf (thePsFont, "%s-Bold", TheFamily[aFontId]); | |
a174a3c5 | 97 | } |
98 | } | |
99 | else if (isItalic) | |
100 | { | |
101 | sprintf (thePsFont, "%s-%s", TheFamily[aFontId], TheItalic[aFontId]); | |
102 | } | |
103 | else | |
104 | { | |
105 | sprintf (thePsFont, "%s%s", TheFamily[aFontId], TheBase[aFontId]); | |
106 | } | |
107 | } | |
2166f0fa | 108 | |
a174a3c5 | 109 | static void exportText (const NCollection_String& theText, |
110 | const Standard_Boolean theIs2d, | |
111 | const OpenGl_AspectText& theAspect, | |
112 | const Standard_Integer theHeight) | |
113 | { | |
2166f0fa | 114 | |
a174a3c5 | 115 | char aPsFont[64]; |
116 | getGL2PSFontName (theAspect.FontName().ToCString(), aPsFont); | |
2166f0fa | 117 | |
ca3c13d1 | 118 | #if !defined(GL_ES_VERSION_2_0) |
a174a3c5 | 119 | if (theIs2d) |
120 | { | |
121 | glRasterPos2f (0.0f, 0.0f); | |
122 | } | |
123 | else | |
124 | { | |
125 | glRasterPos3f (0.0f, 0.0f, 0.0f); | |
126 | } | |
127 | ||
128 | GLubyte aZero = 0; | |
129 | glBitmap (1, 1, 0, 0, 0, 0, &aZero); | |
ca3c13d1 | 130 | #endif |
a174a3c5 | 131 | |
132 | // Standard GL2PS's alignment isn't used, because it doesn't work correctly | |
133 | // for all formats, therefore alignment is calculated manually relative | |
134 | // to the bottom-left corner, which corresponds to the GL2PS_TEXT_BL value | |
105aae76 | 135 | gl2psTextOpt (theText.ToCString(), aPsFont, (GLshort)theHeight, GL2PS_TEXT_BL, theAspect.Angle()); |
a174a3c5 | 136 | } |
137 | #endif | |
138 | ||
68858c7d | 139 | } // anonymous namespace |
a174a3c5 | 140 | |
141 | // ======================================================================= | |
142 | // function : OpenGl_Text | |
143 | // purpose : | |
144 | // ======================================================================= | |
145 | OpenGl_Text::OpenGl_Text() | |
146 | : myWinX (0.0f), | |
147 | myWinY (0.0f), | |
148 | myWinZ (0.0f), | |
149 | myScaleHeight (1.0f), | |
150 | myPoint (0.0f, 0.0f, 0.0f), | |
ce01ec26 | 151 | myIs2d (false), |
3f1eb0ab | 152 | myHasPlane (false), |
153 | myHasAnchorPoint (true) | |
a174a3c5 | 154 | { |
155 | myParams.Height = 10; | |
156 | myParams.HAlign = Graphic3d_HTA_LEFT; | |
157 | myParams.VAlign = Graphic3d_VTA_BOTTOM; | |
2166f0fa SK |
158 | } |
159 | ||
a174a3c5 | 160 | // ======================================================================= |
161 | // function : OpenGl_Text | |
162 | // purpose : | |
163 | // ======================================================================= | |
b64d84be | 164 | OpenGl_Text::OpenGl_Text (const Standard_Utf8Char* theText, |
165 | const OpenGl_Vec3& thePoint, | |
166 | const OpenGl_TextParam& theParams) | |
a174a3c5 | 167 | : myWinX (0.0f), |
168 | myWinY (0.0f), | |
169 | myWinZ (0.0f), | |
170 | myScaleHeight (1.0f), | |
171 | myExportHeight (1.0f), | |
172 | myParams (theParams), | |
b64d84be | 173 | myString (theText), |
a174a3c5 | 174 | myPoint (thePoint), |
ce01ec26 | 175 | myIs2d (false), |
3f1eb0ab | 176 | myHasPlane (false), |
177 | myHasAnchorPoint (true) | |
a174a3c5 | 178 | { |
179 | // | |
180 | } | |
2166f0fa | 181 | |
ce01ec26 | 182 | // ======================================================================= |
183 | // function : OpenGl_Text | |
184 | // purpose : | |
185 | // ======================================================================= | |
186 | OpenGl_Text::OpenGl_Text (const Standard_Utf8Char* theText, | |
187 | const gp_Ax2& theOrientation, | |
3f1eb0ab | 188 | const OpenGl_TextParam& theParams, |
189 | const bool theHasOwnAnchor) | |
ce01ec26 | 190 | : myWinX (0.0), |
191 | myWinY (0.0), | |
192 | myWinZ (0.0), | |
193 | myScaleHeight (1.0), | |
194 | myExportHeight (1.0), | |
195 | myParams (theParams), | |
196 | myString (theText), | |
197 | myIs2d (false), | |
198 | myOrientation (theOrientation), | |
3f1eb0ab | 199 | myHasPlane (true), |
200 | myHasAnchorPoint (theHasOwnAnchor) | |
ce01ec26 | 201 | { |
202 | const gp_Pnt& aPoint = theOrientation.Location(); | |
203 | myPoint = OpenGl_Vec3 (static_cast<Standard_ShortReal> (aPoint.X()), | |
204 | static_cast<Standard_ShortReal> (aPoint.Y()), | |
205 | static_cast<Standard_ShortReal> (aPoint.Z())); | |
206 | } | |
207 | ||
a174a3c5 | 208 | // ======================================================================= |
209 | // function : SetPosition | |
210 | // purpose : | |
211 | // ======================================================================= | |
212 | void OpenGl_Text::SetPosition (const OpenGl_Vec3& thePoint) | |
2166f0fa | 213 | { |
a174a3c5 | 214 | myPoint = thePoint; |
2166f0fa SK |
215 | } |
216 | ||
a174a3c5 | 217 | // ======================================================================= |
218 | // function : SetFontSize | |
219 | // purpose : | |
220 | // ======================================================================= | |
221 | void OpenGl_Text::SetFontSize (const Handle(OpenGl_Context)& theCtx, | |
222 | const Standard_Integer theFontSize) | |
223 | { | |
224 | if (myParams.Height != theFontSize) | |
225 | { | |
10b9c7df | 226 | Release (theCtx.operator->()); |
a174a3c5 | 227 | } |
228 | myParams.Height = theFontSize; | |
229 | } | |
230 | ||
231 | // ======================================================================= | |
232 | // function : Init | |
233 | // purpose : | |
234 | // ======================================================================= | |
235 | void OpenGl_Text::Init (const Handle(OpenGl_Context)& theCtx, | |
236 | const Standard_Utf8Char* theText, | |
237 | const OpenGl_Vec3& thePoint) | |
238 | { | |
10b9c7df | 239 | releaseVbos (theCtx.operator->()); |
a174a3c5 | 240 | myIs2d = false; |
241 | myPoint = thePoint; | |
242 | myString.FromUnicode (theText); | |
243 | } | |
244 | ||
245 | // ======================================================================= | |
246 | // function : Init | |
247 | // purpose : | |
248 | // ======================================================================= | |
249 | void OpenGl_Text::Init (const Handle(OpenGl_Context)& theCtx, | |
250 | const Standard_Utf8Char* theText, | |
251 | const OpenGl_Vec3& thePoint, | |
252 | const OpenGl_TextParam& theParams) | |
253 | { | |
254 | if (myParams.Height != theParams.Height) | |
255 | { | |
10b9c7df | 256 | Release (theCtx.operator->()); |
a174a3c5 | 257 | } |
258 | else | |
259 | { | |
10b9c7df | 260 | releaseVbos (theCtx.operator->()); |
a174a3c5 | 261 | } |
262 | myIs2d = false; | |
263 | myParams = theParams; | |
264 | myPoint = thePoint; | |
265 | myString.FromUnicode (theText); | |
266 | } | |
2166f0fa | 267 | |
a174a3c5 | 268 | // ======================================================================= |
269 | // function : Init | |
270 | // purpose : | |
271 | // ======================================================================= | |
272 | void OpenGl_Text::Init (const Handle(OpenGl_Context)& theCtx, | |
273 | const TCollection_ExtendedString& theText, | |
274 | const OpenGl_Vec2& thePoint, | |
275 | const OpenGl_TextParam& theParams) | |
2166f0fa | 276 | { |
a174a3c5 | 277 | if (myParams.Height != theParams.Height) |
278 | { | |
10b9c7df | 279 | Release (theCtx.operator->()); |
a174a3c5 | 280 | } |
281 | else | |
282 | { | |
10b9c7df | 283 | releaseVbos (theCtx.operator->()); |
a174a3c5 | 284 | } |
285 | myIs2d = true; | |
286 | myParams = theParams; | |
287 | myPoint.xy() = thePoint; | |
288 | myPoint.z() = 0.0f; | |
289 | myString.FromUnicode ((Standard_Utf16Char* )theText.ToExtString()); | |
290 | } | |
291 | ||
292 | // ======================================================================= | |
293 | // function : ~OpenGl_Text | |
294 | // purpose : | |
295 | // ======================================================================= | |
296 | OpenGl_Text::~OpenGl_Text() | |
297 | { | |
298 | // | |
299 | } | |
300 | ||
301 | // ======================================================================= | |
302 | // function : releaseVbos | |
303 | // purpose : | |
304 | // ======================================================================= | |
10b9c7df | 305 | void OpenGl_Text::releaseVbos (OpenGl_Context* theCtx) |
a174a3c5 | 306 | { |
307 | for (Standard_Integer anIter = 0; anIter < myVertsVbo.Length(); ++anIter) | |
308 | { | |
309 | Handle(OpenGl_VertexBuffer)& aVerts = myVertsVbo.ChangeValue (anIter); | |
310 | Handle(OpenGl_VertexBuffer)& aTCrds = myTCrdsVbo.ChangeValue (anIter); | |
311 | ||
10b9c7df | 312 | if (theCtx) |
a174a3c5 | 313 | { |
314 | theCtx->DelayedRelease (aVerts); | |
315 | theCtx->DelayedRelease (aTCrds); | |
316 | } | |
317 | aVerts.Nullify(); | |
318 | aTCrds.Nullify(); | |
319 | } | |
320 | myTextures.Clear(); | |
321 | myVertsVbo.Clear(); | |
322 | myTCrdsVbo.Clear(); | |
a174a3c5 | 323 | } |
324 | ||
325 | // ======================================================================= | |
326 | // function : Release | |
327 | // purpose : | |
328 | // ======================================================================= | |
10b9c7df | 329 | void OpenGl_Text::Release (OpenGl_Context* theCtx) |
a174a3c5 | 330 | { |
331 | releaseVbos (theCtx); | |
332 | if (!myFont.IsNull()) | |
333 | { | |
334 | Handle(OpenGl_Context) aCtx = theCtx; | |
335 | const TCollection_AsciiString aKey = myFont->ResourceKey(); | |
336 | myFont.Nullify(); | |
c04c30b3 | 337 | if (! aCtx.IsNull()) |
10b9c7df | 338 | aCtx->ReleaseResource (aKey, Standard_True); |
a174a3c5 | 339 | } |
340 | } | |
341 | ||
342 | // ======================================================================= | |
343 | // function : StringSize | |
344 | // purpose : | |
345 | // ======================================================================= | |
346 | void OpenGl_Text::StringSize (const Handle(OpenGl_Context)& theCtx, | |
347 | const NCollection_String& theText, | |
348 | const OpenGl_AspectText& theTextAspect, | |
349 | const OpenGl_TextParam& theParams, | |
4b1c8733 | 350 | const unsigned int theResolution, |
a174a3c5 | 351 | Standard_ShortReal& theWidth, |
352 | Standard_ShortReal& theAscent, | |
353 | Standard_ShortReal& theDescent) | |
354 | { | |
355 | theWidth = 0.0f; | |
356 | theAscent = 0.0f; | |
357 | theDescent = 0.0f; | |
4b1c8733 | 358 | const TCollection_AsciiString aFontKey = FontKey (theTextAspect, theParams.Height, theResolution); |
359 | Handle(OpenGl_Font) aFont = FindFont (theCtx, theTextAspect, theParams.Height, theResolution, aFontKey); | |
a174a3c5 | 360 | if (aFont.IsNull() || !aFont->IsValid()) |
361 | { | |
2166f0fa | 362 | return; |
a174a3c5 | 363 | } |
364 | ||
365 | theAscent = aFont->Ascender(); | |
366 | theDescent = aFont->Descender(); | |
367 | ||
368 | GLfloat aWidth = 0.0f; | |
369 | for (NCollection_Utf8Iter anIter = theText.Iterator(); *anIter != 0;) | |
370 | { | |
371 | const Standard_Utf32Char aCharThis = *anIter; | |
372 | const Standard_Utf32Char aCharNext = *++anIter; | |
373 | ||
374 | if (aCharThis == '\x0D' // CR (carriage return) | |
375 | || aCharThis == '\a' // BEL (alarm) | |
376 | || aCharThis == '\f' // FF (form feed) NP (new page) | |
377 | || aCharThis == '\b' // BS (backspace) | |
378 | || aCharThis == '\v') // VT (vertical tab) | |
379 | { | |
380 | continue; // skip unsupported carriage control codes | |
381 | } | |
382 | else if (aCharThis == '\x0A') // LF (line feed, new line) | |
383 | { | |
384 | theWidth = Max (theWidth, aWidth); | |
385 | aWidth = 0.0f; | |
386 | continue; | |
387 | } | |
388 | else if (aCharThis == ' ') | |
389 | { | |
d2eddacc | 390 | aWidth += aFont->FTFont()->AdvanceX (aCharThis, aCharNext); |
a174a3c5 | 391 | continue; |
392 | } | |
393 | else if (aCharThis == '\t') | |
394 | { | |
d2eddacc | 395 | aWidth += aFont->FTFont()->AdvanceX (' ', aCharNext) * 8.0f; |
a174a3c5 | 396 | continue; |
397 | } | |
398 | ||
d2eddacc | 399 | aWidth += aFont->FTFont()->AdvanceX (aCharThis, aCharNext); |
a174a3c5 | 400 | } |
401 | theWidth = Max (theWidth, aWidth); | |
402 | ||
403 | Handle(OpenGl_Context) aCtx = theCtx; | |
404 | aFont.Nullify(); | |
405 | aCtx->ReleaseResource (aFontKey, Standard_True); | |
406 | } | |
407 | ||
408 | // ======================================================================= | |
409 | // function : Render | |
410 | // purpose : | |
411 | // ======================================================================= | |
412 | void OpenGl_Text::Render (const Handle(OpenGl_Workspace)& theWorkspace) const | |
413 | { | |
f9ba5c4d | 414 | const OpenGl_AspectText* aTextAspect = theWorkspace->ApplyAspectText(); |
25ef750e | 415 | const Handle(OpenGl_Texture) aPrevTexture = theWorkspace->DisableTexture(); |
416 | const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext(); | |
30f0ad28 | 417 | |
b990e557 | 418 | // Bind custom shader program or generate default version |
4e1523ef | 419 | if (aCtx->core20fwd != NULL) |
30f0ad28 | 420 | { |
299e0ab9 | 421 | aCtx->ShaderManager()->BindFontProgram (aTextAspect->ShaderProgramRes (aCtx)); |
30f0ad28 | 422 | } |
423 | ||
c357e426 | 424 | myOrientationMatrix = theWorkspace->View()->Camera()->OrientationMatrix(); |
ce01ec26 | 425 | myProjMatrix.Convert (aCtx->ProjectionState.Current()); |
426 | ||
a174a3c5 | 427 | // use highlight color or colors from aspect |
f9ba5c4d | 428 | render (theWorkspace->PrinterContext(), |
429 | aCtx, | |
430 | *aTextAspect, | |
431 | theWorkspace->TextColor(), | |
432 | theWorkspace->TextSubtitleColor(), | |
433 | theWorkspace->View()->RenderingParams().Resolution); | |
2166f0fa | 434 | |
c6ad5e5f | 435 | aCtx->BindProgram (NULL); |
436 | ||
a174a3c5 | 437 | // restore aspects |
438 | if (!aPrevTexture.IsNull()) | |
439 | { | |
440 | theWorkspace->EnableTexture (aPrevTexture); | |
441 | } | |
b34efb62 | 442 | |
443 | // restore Z buffer settings | |
eae454e3 | 444 | if (theWorkspace->UseZBuffer()) |
b34efb62 | 445 | { |
446 | glEnable (GL_DEPTH_TEST); | |
447 | } | |
a174a3c5 | 448 | } |
2166f0fa | 449 | |
a174a3c5 | 450 | // ======================================================================= |
451 | // function : Render | |
452 | // purpose : | |
453 | // ======================================================================= | |
454 | void OpenGl_Text::Render (const Handle(OpenGl_PrinterContext)& thePrintCtx, | |
455 | const Handle(OpenGl_Context)& theCtx, | |
4b1c8733 | 456 | const OpenGl_AspectText& theTextAspect, |
457 | const unsigned int theResolution) const | |
a174a3c5 | 458 | { |
4b1c8733 | 459 | render (thePrintCtx, theCtx, theTextAspect, theTextAspect.Color(), theTextAspect.SubtitleColor(), theResolution); |
a174a3c5 | 460 | } |
2166f0fa | 461 | |
a174a3c5 | 462 | // ======================================================================= |
463 | // function : setupMatrix | |
464 | // purpose : | |
465 | // ======================================================================= | |
466 | void OpenGl_Text::setupMatrix (const Handle(OpenGl_PrinterContext)& thePrintCtx, | |
ca3c13d1 | 467 | const Handle(OpenGl_Context)& theCtx, |
a174a3c5 | 468 | const OpenGl_AspectText& theTextAspect, |
469 | const OpenGl_Vec3 theDVec) const | |
470 | { | |
c827ea3a | 471 | OpenGl_Mat4d aModViewMat; |
ce01ec26 | 472 | OpenGl_Mat4d aProjectMat; |
3f1eb0ab | 473 | if (myHasPlane && myHasAnchorPoint) |
ce01ec26 | 474 | { |
475 | aProjectMat = myProjMatrix * myOrientationMatrix; | |
476 | } | |
477 | else | |
478 | { | |
479 | aProjectMat = myProjMatrix; | |
480 | } | |
c827ea3a | 481 | |
a174a3c5 | 482 | if (myIs2d) |
bf75be98 | 483 | { |
825aa485 | 484 | Graphic3d_TransformUtils::Translate<GLdouble> (aModViewMat, myPoint.x() + theDVec.x(), myPoint.y() + theDVec.y(), 0.f); |
485 | Graphic3d_TransformUtils::Scale<GLdouble> (aModViewMat, 1.f, -1.f, 1.f); | |
486 | Graphic3d_TransformUtils::Rotate<GLdouble> (aModViewMat, theTextAspect.Angle(), 0.f, 0.f, 1.f); | |
2166f0fa SK |
487 | } |
488 | else | |
489 | { | |
a174a3c5 | 490 | // align coordinates to the nearest integer |
491 | // to avoid extra interpolation issues | |
492 | GLdouble anObjX, anObjY, anObjZ; | |
825aa485 | 493 | Graphic3d_TransformUtils::UnProject<Standard_Real> (std::floor (myWinX + theDVec.x()), |
494 | std::floor (myWinY + theDVec.y()), | |
495 | myWinZ + theDVec.z(), | |
496 | OpenGl_Mat4d::Map (THE_IDENTITY_MATRIX), | |
ce01ec26 | 497 | OpenGl_Mat4d::Map (aProjectMat), |
825aa485 | 498 | myViewport, |
499 | anObjX, | |
500 | anObjY, | |
501 | anObjZ); | |
502 | ||
ce01ec26 | 503 | if (myHasPlane) |
504 | { | |
505 | const gp_Dir& aVectorDir = myOrientation.XDirection(); | |
506 | const gp_Dir& aVectorUp = myOrientation.Direction(); | |
507 | const gp_Dir& aVectorRight = myOrientation.YDirection(); | |
508 | ||
ce01ec26 | 509 | aModViewMat.SetColumn (2, OpenGl_Vec3d (aVectorUp.X(), aVectorUp.Y(), aVectorUp.Z())); |
510 | aModViewMat.SetColumn (1, OpenGl_Vec3d (aVectorRight.X(), aVectorRight.Y(), aVectorRight.Z())); | |
511 | aModViewMat.SetColumn (0, OpenGl_Vec3d (aVectorDir.X(), aVectorDir.Y(), aVectorDir.Z())); | |
3f1eb0ab | 512 | |
513 | if (!myHasAnchorPoint) | |
514 | { | |
515 | OpenGl_Mat4d aPosMat; | |
516 | aPosMat.SetColumn (3, OpenGl_Vec3d (myPoint.x(), myPoint.y(), myPoint.z())); | |
517 | aPosMat *= aModViewMat; | |
518 | aModViewMat.SetColumn (3, aPosMat.GetColumn (3)); | |
519 | } | |
520 | else | |
521 | { | |
522 | aModViewMat.SetColumn (3, OpenGl_Vec3d (anObjX, anObjY, anObjZ)); | |
523 | } | |
ce01ec26 | 524 | } |
525 | else | |
526 | { | |
527 | Graphic3d_TransformUtils::Translate<GLdouble> (aModViewMat, anObjX, anObjY, anObjZ); | |
528 | Graphic3d_TransformUtils::Rotate<GLdouble> (aModViewMat, theTextAspect.Angle(), 0.0, 0.0, 1.0); | |
529 | } | |
825aa485 | 530 | |
a174a3c5 | 531 | if (!theTextAspect.IsZoomable()) |
532 | { | |
533 | #ifdef _WIN32 | |
534 | // if the context has assigned printer context, use it's parameters | |
535 | if (!thePrintCtx.IsNull()) | |
536 | { | |
537 | // get printing scaling in x and y dimensions | |
538 | GLfloat aTextScalex = 1.0f, aTextScaley = 1.0f; | |
539 | thePrintCtx->GetScale (aTextScalex, aTextScaley); | |
540 | ||
541 | // text should be scaled in all directions with same | |
542 | // factor to save its proportions, so use height (y) scaling | |
543 | // as it is better for keeping text/3d graphics proportions | |
825aa485 | 544 | Graphic3d_TransformUtils::Scale<GLdouble> (aModViewMat, aTextScaley, aTextScaley, aTextScaley); |
a174a3c5 | 545 | } |
c85385c0 | 546 | #else |
547 | (void )thePrintCtx; | |
a174a3c5 | 548 | #endif |
825aa485 | 549 | Graphic3d_TransformUtils::Scale<GLdouble> (aModViewMat, myScaleHeight, myScaleHeight, myScaleHeight); |
a174a3c5 | 550 | } |
551 | } | |
c827ea3a | 552 | |
3f1eb0ab | 553 | if (myHasPlane && !myHasAnchorPoint) |
554 | { | |
555 | OpenGl_Mat4d aCurrentWorldViewMat; | |
556 | aCurrentWorldViewMat.Convert (theCtx->WorldViewState.Current()); | |
557 | theCtx->WorldViewState.SetCurrent<Standard_Real> (aCurrentWorldViewMat * aModViewMat); | |
558 | } | |
559 | else | |
560 | { | |
561 | theCtx->WorldViewState.SetCurrent<Standard_Real> (aModViewMat); | |
562 | } | |
c827ea3a | 563 | theCtx->ApplyWorldViewMatrix(); |
b990e557 | 564 | |
ce01ec26 | 565 | if (!myIs2d) |
566 | { | |
567 | theCtx->ProjectionState.SetCurrent<Standard_Real> (aProjectMat); | |
568 | theCtx->ApplyProjectionMatrix(); | |
569 | } | |
570 | ||
b990e557 | 571 | if (!theCtx->ActiveProgram().IsNull()) |
572 | { | |
573 | // Upload updated state to shader program | |
574 | theCtx->ShaderManager()->PushState (theCtx->ActiveProgram()); | |
575 | } | |
a174a3c5 | 576 | } |
577 | ||
578 | // ======================================================================= | |
579 | // function : drawText | |
580 | // purpose : | |
581 | // ======================================================================= | |
35e08fe8 | 582 | |
583 | void OpenGl_Text::drawText (const Handle(OpenGl_PrinterContext)& , | |
a174a3c5 | 584 | const Handle(OpenGl_Context)& theCtx, |
35e08fe8 | 585 | #ifdef HAVE_GL2PS |
a174a3c5 | 586 | const OpenGl_AspectText& theTextAspect) const |
35e08fe8 | 587 | #else |
588 | const OpenGl_AspectText& ) const | |
589 | #endif | |
a174a3c5 | 590 | { |
591 | #ifdef HAVE_GL2PS | |
592 | if (theCtx->IsFeedback()) | |
593 | { | |
594 | // position of the text and alignment is calculated by transformation matrix | |
595 | exportText (myString, myIs2d, theTextAspect, (Standard_Integer )myExportHeight); | |
596 | return; | |
2166f0fa | 597 | } |
a174a3c5 | 598 | #endif |
2166f0fa | 599 | |
7d3e64ef | 600 | if (myVertsVbo.Length() != myTextures.Length() |
601 | || myTextures.IsEmpty()) | |
2166f0fa | 602 | { |
7d3e64ef | 603 | return; |
2166f0fa | 604 | } |
7d3e64ef | 605 | |
606 | for (Standard_Integer anIter = 0; anIter < myTextures.Length(); ++anIter) | |
a174a3c5 | 607 | { |
7d3e64ef | 608 | const GLuint aTexId = myTextures.Value (anIter); |
609 | glBindTexture (GL_TEXTURE_2D, aTexId); | |
a174a3c5 | 610 | |
7d3e64ef | 611 | const Handle(OpenGl_VertexBuffer)& aVerts = myVertsVbo.Value (anIter); |
612 | const Handle(OpenGl_VertexBuffer)& aTCrds = myTCrdsVbo.Value (anIter); | |
613 | aVerts->BindAttribute (theCtx, Graphic3d_TOA_POS); | |
614 | aTCrds->BindAttribute (theCtx, Graphic3d_TOA_UV); | |
2166f0fa | 615 | |
7d3e64ef | 616 | glDrawArrays (GL_TRIANGLES, 0, GLsizei(aVerts->GetElemsNb())); |
2166f0fa | 617 | |
b990e557 | 618 | aTCrds->UnbindAttribute (theCtx, Graphic3d_TOA_UV); |
7d3e64ef | 619 | aVerts->UnbindAttribute (theCtx, Graphic3d_TOA_POS); |
a174a3c5 | 620 | } |
7d3e64ef | 621 | glBindTexture (GL_TEXTURE_2D, 0); |
a174a3c5 | 622 | } |
2166f0fa | 623 | |
a174a3c5 | 624 | // ======================================================================= |
625 | // function : FontKey | |
626 | // purpose : | |
627 | // ======================================================================= | |
628 | TCollection_AsciiString OpenGl_Text::FontKey (const OpenGl_AspectText& theAspect, | |
4b1c8733 | 629 | const Standard_Integer theHeight, |
630 | const unsigned int theResolution) | |
a174a3c5 | 631 | { |
632 | const Font_FontAspect anAspect = (theAspect.FontAspect() != Font_FA_Undefined) ? theAspect.FontAspect() : Font_FA_Regular; | |
633 | return theAspect.FontName() | |
634 | + TCollection_AsciiString(":") + Standard_Integer(anAspect) | |
4b1c8733 | 635 | + TCollection_AsciiString(":") + Standard_Integer(theResolution) |
a174a3c5 | 636 | + TCollection_AsciiString(":") + theHeight; |
637 | } | |
638 | ||
639 | // ======================================================================= | |
640 | // function : FindFont | |
641 | // purpose : | |
642 | // ======================================================================= | |
643 | Handle(OpenGl_Font) OpenGl_Text::FindFont (const Handle(OpenGl_Context)& theCtx, | |
644 | const OpenGl_AspectText& theAspect, | |
645 | const Standard_Integer theHeight, | |
4b1c8733 | 646 | const unsigned int theResolution, |
a174a3c5 | 647 | const TCollection_AsciiString theKey) |
648 | { | |
649 | Handle(OpenGl_Font) aFont; | |
650 | if (theHeight < 2) | |
2166f0fa | 651 | { |
a174a3c5 | 652 | return aFont; // invalid parameters |
653 | } | |
2166f0fa | 654 | |
a174a3c5 | 655 | if (!theCtx->GetResource (theKey, aFont)) |
656 | { | |
657 | Handle(Font_FontMgr) aFontMgr = Font_FontMgr::GetInstance(); | |
658 | const Handle(TCollection_HAsciiString) aFontName = new TCollection_HAsciiString (theAspect.FontName()); | |
659 | const Font_FontAspect anAspect = (theAspect.FontAspect() != Font_FA_Undefined) ? theAspect.FontAspect() : Font_FA_Regular; | |
660 | Handle(Font_SystemFont) aRequestedFont = aFontMgr->FindFont (aFontName, anAspect, theHeight); | |
65360da3 | 661 | Handle(Font_FTFont) aFontFt; |
662 | if (!aRequestedFont.IsNull()) | |
2166f0fa | 663 | { |
65360da3 | 664 | aFontFt = new Font_FTFont (NULL); |
317d68c9 | 665 | |
4b1c8733 | 666 | if (aFontFt->Init (aRequestedFont->FontPath()->ToCString(), theHeight, theResolution)) |
65360da3 | 667 | { |
668 | aFont = new OpenGl_Font (aFontFt, theKey); | |
669 | if (!aFont->Init (theCtx)) | |
670 | { | |
671 | TCollection_ExtendedString aMsg; | |
672 | aMsg += "Font '"; | |
673 | aMsg += theAspect.FontName(); | |
674 | aMsg += "' - initialization of GL resources has failed!"; | |
3b523c4c | 675 | theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, aMsg); |
65360da3 | 676 | aFontFt.Nullify(); |
c6ad5e5f | 677 | aFont->Release (theCtx.operator->()); |
65360da3 | 678 | aFont = new OpenGl_Font (aFontFt, theKey); |
679 | } | |
680 | } | |
681 | else | |
682 | { | |
683 | TCollection_ExtendedString aMsg; | |
684 | aMsg += "Font '"; | |
685 | aMsg += theAspect.FontName(); | |
686 | aMsg += "' is broken or has incompatible format! File path: "; | |
687 | aMsg += aRequestedFont->FontPath()->ToCString(); | |
3b523c4c | 688 | theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, aMsg); |
65360da3 | 689 | aFontFt.Nullify(); |
690 | aFont = new OpenGl_Font (aFontFt, theKey); | |
691 | } | |
a174a3c5 | 692 | } |
65360da3 | 693 | else |
a174a3c5 | 694 | { |
65360da3 | 695 | TCollection_ExtendedString aMsg; |
696 | aMsg += "Font '"; | |
697 | aMsg += theAspect.FontName(); | |
698 | aMsg += "' is not found in the system!"; | |
3b523c4c | 699 | theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, aMsg); |
65360da3 | 700 | aFont = new OpenGl_Font (aFontFt, theKey); |
a174a3c5 | 701 | } |
a174a3c5 | 702 | |
b34efb62 | 703 | theCtx->ShareResource (theKey, aFont); |
a174a3c5 | 704 | } |
705 | return aFont; | |
706 | } | |
707 | ||
708 | // ======================================================================= | |
709 | // function : render | |
710 | // purpose : | |
711 | // ======================================================================= | |
712 | void OpenGl_Text::render (const Handle(OpenGl_PrinterContext)& thePrintCtx, | |
713 | const Handle(OpenGl_Context)& theCtx, | |
714 | const OpenGl_AspectText& theTextAspect, | |
715 | const TEL_COLOUR& theColorText, | |
4b1c8733 | 716 | const TEL_COLOUR& theColorSubs, |
717 | const unsigned int theResolution) const | |
a174a3c5 | 718 | { |
719 | if (myString.IsEmpty()) | |
720 | { | |
721 | return; | |
722 | } | |
723 | ||
4b1c8733 | 724 | // Note that using difference resolution in different Views in same Viewer |
725 | // will lead to performance regression (for example, text will be recreated every time). | |
726 | const TCollection_AsciiString aFontKey = FontKey (theTextAspect, myParams.Height, theResolution); | |
a174a3c5 | 727 | if (!myFont.IsNull() |
728 | && !myFont->ResourceKey().IsEqual (aFontKey)) | |
729 | { | |
730 | // font changed | |
10b9c7df | 731 | const_cast<OpenGl_Text* > (this)->Release (theCtx.operator->()); |
a174a3c5 | 732 | } |
733 | ||
734 | if (myFont.IsNull()) | |
735 | { | |
4b1c8733 | 736 | myFont = FindFont (theCtx, theTextAspect, myParams.Height, theResolution, aFontKey); |
65360da3 | 737 | } |
738 | if (!myFont->WasInitialized()) | |
739 | { | |
740 | return; | |
a174a3c5 | 741 | } |
742 | ||
743 | if (myTextures.IsEmpty()) | |
744 | { | |
317d68c9 | 745 | Font_TextFormatter aFormatter; |
a174a3c5 | 746 | aFormatter.SetupAlignment (myParams.HAlign, myParams.VAlign); |
747 | aFormatter.Reset(); | |
317d68c9 | 748 | |
d2eddacc | 749 | aFormatter.Append (myString, *myFont->FTFont().operator->()); |
a174a3c5 | 750 | aFormatter.Format(); |
751 | ||
317d68c9 | 752 | OpenGl_TextBuilder aBuilder; |
753 | aBuilder.Perform (aFormatter, | |
754 | theCtx, | |
755 | *myFont.operator->(), | |
756 | myTextures, | |
757 | myVertsVbo, | |
758 | myTCrdsVbo); | |
759 | ||
a174a3c5 | 760 | aFormatter.BndBox (myBndBox); |
761 | } | |
762 | ||
763 | if (myTextures.IsEmpty()) | |
764 | { | |
765 | return; | |
766 | } | |
767 | ||
768 | myExportHeight = 1.0f; | |
769 | myScaleHeight = 1.0f; | |
770 | ||
3f1eb0ab | 771 | if (myHasPlane && !myHasAnchorPoint) |
772 | { | |
773 | OpenGl_Mat4d aWorldViewMat; | |
774 | aWorldViewMat.Convert (theCtx->WorldViewState.Current()); | |
775 | theCtx->WorldViewState.Push(); | |
776 | theCtx->WorldViewState.SetCurrent<Standard_Real> (aWorldViewMat); | |
777 | theCtx->ApplyWorldViewMatrix(); | |
778 | } | |
779 | else | |
780 | { | |
781 | theCtx->WorldViewState.Push(); | |
782 | } | |
c827ea3a | 783 | |
c827ea3a | 784 | myModelMatrix.Convert (theCtx->WorldViewState.Current() * theCtx->ModelWorldState.Current()); |
785 | ||
a174a3c5 | 786 | if (!myIs2d) |
787 | { | |
a174a3c5 | 788 | glGetIntegerv (GL_VIEWPORT, myViewport); |
c827ea3a | 789 | |
825aa485 | 790 | Graphic3d_TransformUtils::Project<Standard_Real> (myPoint.x(), |
791 | myPoint.y(), | |
792 | myPoint.z(), | |
793 | myModelMatrix, | |
794 | myProjMatrix, | |
795 | myViewport, | |
796 | myWinX, | |
797 | myWinY, | |
798 | myWinZ); | |
a174a3c5 | 799 | |
800 | // compute scale factor for constant text height | |
801 | GLdouble x1, y1, z1; | |
825aa485 | 802 | Graphic3d_TransformUtils::UnProject<Standard_Real> (myWinX, |
803 | myWinY, | |
804 | myWinZ, | |
805 | OpenGl_Mat4d::Map (THE_IDENTITY_MATRIX), | |
806 | myProjMatrix, | |
807 | myViewport, | |
808 | x1, | |
809 | y1, | |
810 | z1); | |
a174a3c5 | 811 | |
812 | GLdouble x2, y2, z2; | |
813 | const GLdouble h = (GLdouble )myFont->FTFont()->PointSize(); | |
825aa485 | 814 | Graphic3d_TransformUtils::UnProject<Standard_Real> (myWinX, |
815 | myWinY + h, | |
816 | myWinZ, | |
817 | OpenGl_Mat4d::Map (THE_IDENTITY_MATRIX), | |
818 | myProjMatrix, | |
819 | myViewport, | |
820 | x2, | |
821 | y2, | |
822 | z2); | |
a174a3c5 | 823 | |
824 | myScaleHeight = (y2 - y1) / h; | |
825 | if (theTextAspect.IsZoomable()) | |
826 | { | |
827 | myExportHeight = (float )h; | |
828 | } | |
829 | } | |
830 | myExportHeight = (float )myFont->FTFont()->PointSize() / myExportHeight; | |
831 | ||
b990e557 | 832 | #if !defined(GL_ES_VERSION_2_0) |
65360da3 | 833 | if (theCtx->core11 != NULL) |
834 | { | |
835 | glDisable (GL_LIGHTING); | |
836 | } | |
837 | #endif | |
a174a3c5 | 838 | |
839 | // setup depth test | |
eae454e3 | 840 | if (myIs2d |
841 | || theTextAspect.StyleType() == Aspect_TOST_ANNOTATION) | |
a174a3c5 | 842 | { |
843 | glDisable (GL_DEPTH_TEST); | |
844 | } | |
845 | ||
65360da3 | 846 | if (theCtx->core15fwd != NULL) |
a174a3c5 | 847 | { |
65360da3 | 848 | theCtx->core15fwd->glActiveTexture (GL_TEXTURE0); |
a174a3c5 | 849 | } |
65360da3 | 850 | #if !defined(GL_ES_VERSION_2_0) |
a174a3c5 | 851 | // activate texture unit |
65360da3 | 852 | GLint aTexEnvParam = GL_REPLACE; |
853 | if (theCtx->core11 != NULL) | |
a174a3c5 | 854 | { |
c6ad5e5f | 855 | // setup alpha test |
856 | glAlphaFunc (GL_GEQUAL, 0.285f); | |
857 | glEnable (GL_ALPHA_TEST); | |
858 | ||
65360da3 | 859 | glDisable (GL_TEXTURE_1D); |
860 | glEnable (GL_TEXTURE_2D); | |
861 | glGetTexEnviv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, &aTexEnvParam); | |
862 | if (aTexEnvParam != GL_REPLACE) | |
863 | { | |
864 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); | |
865 | } | |
a174a3c5 | 866 | } |
65360da3 | 867 | #endif |
868 | ||
869 | // setup blending | |
870 | glEnable (GL_BLEND); | |
871 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | |
a174a3c5 | 872 | |
873 | // extra drawings | |
874 | switch (theTextAspect.DisplayType()) | |
875 | { | |
2166f0fa | 876 | case Aspect_TODT_BLEND: |
a174a3c5 | 877 | { |
65360da3 | 878 | #if !defined(GL_ES_VERSION_2_0) |
a174a3c5 | 879 | glEnable (GL_COLOR_LOGIC_OP); |
880 | glLogicOp (GL_XOR); | |
65360da3 | 881 | #endif |
2166f0fa | 882 | break; |
a174a3c5 | 883 | } |
2166f0fa SK |
884 | case Aspect_TODT_SUBTITLE: |
885 | { | |
65360da3 | 886 | #if !defined(GL_ES_VERSION_2_0) |
887 | if (theCtx->core11 != NULL) | |
888 | { | |
299e0ab9 | 889 | theCtx->SetColor4fv (*(const OpenGl_Vec4* )theColorSubs.rgb); |
65360da3 | 890 | setupMatrix (thePrintCtx, theCtx, theTextAspect, OpenGl_Vec3 (0.0f, 0.0f, 0.00001f)); |
891 | ||
892 | glBindTexture (GL_TEXTURE_2D, 0); | |
893 | glBegin (GL_QUADS); | |
894 | glVertex2f (myBndBox.Left, myBndBox.Top); | |
895 | glVertex2f (myBndBox.Right, myBndBox.Top); | |
896 | glVertex2f (myBndBox.Right, myBndBox.Bottom); | |
897 | glVertex2f (myBndBox.Left, myBndBox.Bottom); | |
898 | glEnd(); | |
899 | } | |
900 | #endif | |
2166f0fa SK |
901 | break; |
902 | } | |
2166f0fa | 903 | case Aspect_TODT_DEKALE: |
a174a3c5 | 904 | { |
b990e557 | 905 | theCtx->SetColor4fv (*(const OpenGl_Vec4* )theColorSubs.rgb); |
a174a3c5 | 906 | setupMatrix (thePrintCtx, theCtx, theTextAspect, OpenGl_Vec3 (+1.0f, +1.0f, 0.00001f)); |
907 | drawText (thePrintCtx, theCtx, theTextAspect); | |
908 | setupMatrix (thePrintCtx, theCtx, theTextAspect, OpenGl_Vec3 (-1.0f, -1.0f, 0.00001f)); | |
909 | drawText (thePrintCtx, theCtx, theTextAspect); | |
910 | setupMatrix (thePrintCtx, theCtx, theTextAspect, OpenGl_Vec3 (-1.0f, +1.0f, 0.00001f)); | |
911 | drawText (thePrintCtx, theCtx, theTextAspect); | |
912 | setupMatrix (thePrintCtx, theCtx, theTextAspect, OpenGl_Vec3 (+1.0f, -1.0f, 0.00001f)); | |
913 | drawText (thePrintCtx, theCtx, theTextAspect); | |
914 | break; | |
915 | } | |
a6eb515f | 916 | case Aspect_TODT_DIMENSION: |
a174a3c5 | 917 | case Aspect_TODT_NORMAL: |
918 | { | |
2166f0fa SK |
919 | break; |
920 | } | |
921 | } | |
922 | ||
a174a3c5 | 923 | // main draw call |
b990e557 | 924 | theCtx->SetColor4fv (*(const OpenGl_Vec4* )theColorText.rgb); |
a174a3c5 | 925 | setupMatrix (thePrintCtx, theCtx, theTextAspect, OpenGl_Vec3 (0.0f, 0.0f, 0.0f)); |
926 | drawText (thePrintCtx, theCtx, theTextAspect); | |
2166f0fa | 927 | |
ce01ec26 | 928 | if (!myIs2d) |
929 | { | |
930 | theCtx->ProjectionState.SetCurrent<Standard_Real> (myProjMatrix); | |
931 | theCtx->ApplyProjectionMatrix(); | |
932 | } | |
933 | ||
65360da3 | 934 | #if !defined(GL_ES_VERSION_2_0) |
935 | if (theCtx->core11 != NULL) | |
936 | { | |
937 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, aTexEnvParam); | |
938 | } | |
939 | #endif | |
543f0db0 | 940 | |
941 | if (theTextAspect.DisplayType() == Aspect_TODT_DIMENSION) | |
942 | { | |
943 | setupMatrix (thePrintCtx, theCtx, theTextAspect, OpenGl_Vec3 (0.0f, 0.0f, 0.00001f)); | |
944 | ||
945 | glDisable (GL_BLEND); | |
543f0db0 | 946 | if (!myIs2d) |
947 | { | |
948 | glDisable (GL_DEPTH_TEST); | |
949 | } | |
65360da3 | 950 | #if !defined(GL_ES_VERSION_2_0) |
951 | if (theCtx->core11 != NULL) | |
952 | { | |
953 | glDisable (GL_TEXTURE_2D); | |
954 | glDisable (GL_ALPHA_TEST); | |
955 | } | |
956 | #endif | |
543f0db0 | 957 | glColorMask (GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); |
958 | ||
959 | glClear (GL_STENCIL_BUFFER_BIT); | |
960 | glEnable (GL_STENCIL_TEST); | |
961 | glStencilFunc (GL_ALWAYS, 1, 0xFF); | |
962 | glStencilOp (GL_KEEP, GL_KEEP, GL_REPLACE); | |
963 | ||
65360da3 | 964 | #if !defined(GL_ES_VERSION_2_0) |
965 | if (theCtx->core11 != NULL) | |
966 | { | |
967 | glBegin (GL_QUADS); | |
968 | glVertex2f (myBndBox.Left, myBndBox.Top); | |
969 | glVertex2f (myBndBox.Right, myBndBox.Top); | |
970 | glVertex2f (myBndBox.Right, myBndBox.Bottom); | |
971 | glVertex2f (myBndBox.Left, myBndBox.Bottom); | |
972 | glEnd(); | |
973 | } | |
974 | #endif | |
543f0db0 | 975 | |
976 | glStencilFunc (GL_ALWAYS, 0, 0xFF); | |
543f0db0 | 977 | |
978 | glColorMask (GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); | |
979 | } | |
980 | ||
b34efb62 | 981 | // reset OpenGL state |
982 | glDisable (GL_BLEND); | |
b34efb62 | 983 | glDisable (GL_STENCIL_TEST); |
65360da3 | 984 | #if !defined(GL_ES_VERSION_2_0) |
c6ad5e5f | 985 | if (theCtx->core11 != NULL) |
986 | { | |
987 | glDisable (GL_ALPHA_TEST); | |
988 | } | |
b34efb62 | 989 | glDisable (GL_COLOR_LOGIC_OP); |
65360da3 | 990 | #endif |
c827ea3a | 991 | |
992 | // model view matrix was modified | |
993 | theCtx->WorldViewState.Pop(); | |
994 | theCtx->ApplyModelViewMatrix(); | |
5e27df78 | 995 | } |