Developer Documentation
TextNodeGLCompat.cc
1 /*===========================================================================*\
2  * *
3  * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39  * *
40 \*===========================================================================*/
41 
42 
43 
44 
45 
46 
47 //=============================================================================
48 //
49 // CLASS TextNode - IMPLEMENTATION
50 //
51 //=============================================================================
52 
53 
54 
55 //== INCLUDES =================================================================
56 
57 #include <ACG/GL/acg_glew.hh>
58 
59 #include "TextNode.hh"
60 #include "../Utils/ImageConversion.hh"
61 
62 
63 //== NAMESPACES ===============================================================
64 
65 namespace ACG {
66 namespace SceneGraph {
67 
68 
69 //== IMPLEMENTATION ==========================================================
70 
71 void
72 TextNode::
73 enterCompat(GLState& _state, const DrawModes::DrawMode& /*_drawmode*/) {
74  if (text_.empty())
75  return;
76 
77  // store current gl state
78  cullFaceEnabled_ = glIsEnabled(GL_CULL_FACE);
79  texture2dEnabled_ = glIsEnabled(GL_TEXTURE_2D);
80  blendEnabled_ = glIsEnabled(GL_BLEND);
81  depthEnabled_ = glIsEnabled(GL_DEPTH_TEST);
82  //alphaTest_ = glIsEnabled(GL_ALPHA_TEST);
83  if (alphaTest_)
85 
86  glGetIntegerv(GL_BLEND_SRC, &blendSrc_);
87  glGetIntegerv(GL_BLEND_DST, &blendDest_);
88 
89  // set texture and drawing states
90  ACG::GLState::disable(GL_CULL_FACE);
91  ACG::GLState::enable(GL_TEXTURE_2D);
92  ACG::GLState::enable(GL_BLEND);
93  ACG::GLState::enable(GL_ALPHA_TEST);
94  ACG::GLState::alphaFunc(GL_GREATER, 0.2f);
95  ACG::GLState::blendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
96  if (alwaysOnTop_)
97  ACG::GLState::disable(GL_DEPTH_TEST);
98 }
99 
100 
101 
102 //----------------------------------------------------------------------------
103 
104 
105 void
106 TextNode::
107 leaveCompat(GLState& /*_state*/, const DrawModes::DrawMode& /*_drawmode*/) {
108  if (text_.empty())
109  return;
110 
111  // restore the GLState as it was when entering TextNode
112  if (cullFaceEnabled_)
113  ACG::GLState::enable(GL_CULL_FACE);
114  if (!texture2dEnabled_)
115  ACG::GLState::disable(GL_TEXTURE_2D);
116  if (!blendEnabled_)
117  ACG::GLState::disable(GL_BLEND);
118  if (depthEnabled_)
119  ACG::GLState::enable(GL_DEPTH_TEST);
120  else
121  ACG::GLState::disable(GL_DEPTH_TEST);
122  if (!alphaTest_)
123  ACG::GLState::disable(GL_ALPHA_TEST);
124  else
126 
128 }
129 
130 //=============================================================================
131 } // namespace SceneGraph
132 } // namespace ACG
133 //=============================================================================
bool depthEnabled_
stores if GL_DEPTH_TEST was enabled on entering TextNode
Definition: TextNode.hh:233
GLint blendDest_
stores the dfactor parameter of glBlendFunc on entering TextNode
Definition: TextNode.hh:251
Namespace providing different geometric functions concerning angles.
static void alphaFunc(GLenum _func, GLclampf _ref)
replaces glAlphaFunc, supports locking
static void disable(GLenum _cap, bool _warnRemoved=true)
replaces glDisable, but supports locking
bool alphaTest_
stores if the alpha test was enabled
Definition: TextNode.hh:239
bool texture2dEnabled_
stores if GL_TEXTURE_2D was enabled on entering TextNode
Definition: TextNode.hh:227
bool blendEnabled_
stores if GL_BLEND was enabled on entering TextNode
Definition: TextNode.hh:224
GLint blendSrc_
stores the sfactor parameter of glBlendFunc on entering TextNode
Definition: TextNode.hh:248
bool cullFaceEnabled_
stores if GL_CULL_FACE was enabled on entering TextNode
Definition: TextNode.hh:230
GLenum alphaTestFunc_
stores alpha test comparison function
Definition: TextNode.hh:245
float alphaTestValue_
stores the alpha value used for alpha test
Definition: TextNode.hh:242
bool alwaysOnTop_
stores if text should be drawn always on top
Definition: TextNode.hh:236
static void getAlphaFunc(GLenum *_func, GLclampf *_ref)
get alpha function, null-ptr safe
static void blendFunc(GLenum _sfactor, GLenum _dfactor)
replaces glBlendFunc, supports locking
static void enable(GLenum _cap, bool _warnRemoved=true)
replaces glEnable, but supports locking
std::string text_
text to be displayed on quads in vbo_
Definition: TextNode.hh:208