NCBI C++ ToolKit
glbackground.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: glbackground.cpp 15168 2007-10-15 19:11:34Z dicuccio $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Authors: Mike DiCuccio
27  *
28  * File Description:
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
34 #include <gui/opengl/gltexture.hpp>
35 
37 
38 
40  : m_Type(eSolid),
41  m_LightColor(1.0f, 1.0f, 1.0f, 1.0f),
42  m_DarkColor(1.0f, 1.0f, 1.0f, 1.0f)
43 {
44 }
45 
46 
48 {
49 }
50 
51 
53 {
54  m_Type = type;
55 }
56 
57 
59 {
60  m_Texture.Reset(&image);
61 }
62 
63 
65 {
66  SetLightColor(c);
67 }
68 
69 
71 {
72  m_LightColor = c;
73 }
74 
75 
77 {
78  m_DarkColor = c;
79 }
80 
81 
83 {
84  // we set the dark color as a fraction of the light color
88 
89  // this doesn't apply to the alpha!
91 }
92 
93 
95 {
96  glPushAttrib(GL_VIEWPORT_BIT);
97  glViewport(vp.Left(), vp.Bottom(), vp.Width(), vp.Height());
98  Draw();
99  glPopAttrib();
100 }
101 
102 
104 {
105  //
106  // matrix set-up
107  // we use an orthographic view, and save all matrices
108  //
109  glMatrixMode(GL_PROJECTION);
110  glPushMatrix();
111  glLoadIdentity();
112  glOrtho(-1, 1, -1, 1, -1, 1);
113 
114  glMatrixMode(GL_MODELVIEW);
115  glPushMatrix();
116  glLoadIdentity();
117 
118  // we also save the enables, as we plan to enable/disable a lot of things
119  glPushAttrib(GL_ENABLE_BIT);
120 
121  // disable the expensive tests
122  glDisable(GL_CULL_FACE);
123  glDisable(GL_DEPTH_TEST);
124  glDisable(GL_BLEND);
125 
126 
127  switch (m_Type) {
128  case eSolid:
129  // solid background
130  // we use only m_LightColor here
131  glDisable(GL_TEXTURE_2D);
132  glColor3fv(m_LightColor.GetColorArray());
133  glBegin(GL_QUADS);
134  glVertex2i( 1, -1);
135  glVertex2i( 1, 1);
136  glVertex2i(-1, 1);
137  glVertex2i(-1, -1);
138  glEnd();
139  break;
140 
141  case eGradientDown:
142  // gradient from top->bottom, light->dark
143  // there is no requirement that light be brighter than dark
144  glDisable(GL_TEXTURE_2D);
145  glBegin(GL_QUADS);
146  glColor3fv(m_LightColor.GetColorArray());
147  glVertex2i(-1, 1);
148  glVertex2i( 1, 1);
149 
150  glColor3fv(m_DarkColor.GetColorArray());
151  glVertex2i( 1, -1);
152  glVertex2i(-1, -1);
153  glEnd();
154  break;
155 
156  case eGradientRight:
157  // gradient from top->bottom, light->dark
158  // there is no requirement that light be brighter than dark
159  glDisable(GL_TEXTURE_2D);
160  glBegin(GL_QUADS);
161  glColor3fv(m_LightColor.GetColorArray());
162  glVertex2i(-1, 1);
163  glVertex2i(-1, -1);
164 
165  glColor3fv(m_DarkColor.GetColorArray());
166  glVertex2i( 1, -1);
167  glVertex2i( 1, 1);
168  glEnd();
169  break;
170 
171  case eTexture:
172  // use a texture, if possible. Otherwise, this is the same as a solid
173  // background
174  // make our texture current if it is available
175  if (m_Texture) {
176  glEnable(GL_TEXTURE_2D);
178  // this is always rendered with a white background
179  glColor3f(1.0f, 1.0f, 1.0f);
180  } else {
181  glDisable(GL_TEXTURE_2D);
182  glColor3fv(m_LightColor.GetColorArray());
183  }
184 
185  glBegin(GL_QUADS);
186  glTexCoord2f(0.0f, 0.0f);
187  glVertex2i(-1, 1);
188 
189  glTexCoord2f(1.0f, 0.0f);
190  glVertex2i( 1, 1);
191 
192  glTexCoord2f(1.0f, 1.0f);
193  glVertex2i( 1, -1);
194 
195  glTexCoord2f(0.0f, 1.0f);
196  glVertex2i(-1, -1);
197  glEnd();
198  break;
199  }
200 
201  //
202  // restore our states
203  // this is done so as to leave the modelview matrix as the last active
204  // matrix
205  //
206  glPopAttrib();
207 
208  glMatrixMode (GL_PROJECTION);
209  glPopMatrix();
210 
211  glMatrixMode (GL_MODELVIEW);
212  glPopMatrix();
213 
214 }
215 
216 
void MakeCurrent()
Definition: gltexture.cpp:228
T Left() const
Definition: glrect.hpp:81
void SetColor(const CRgbaColor &c)
void SetAlpha(float r)
Definition: rgba_color.cpp:287
void Draw(void)
float GetRed(void) const
Get specific channels in floating point values.
Definition: rgba_color.hpp:315
void SetTexture(CGlTexture &tex)
float GetAlpha(void) const
Definition: rgba_color.hpp:333
T Width() const
Definition: glrect.hpp:86
void SetGreen(float r)
Definition: rgba_color.cpp:275
static int type
Definition: getdata.c:34
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:101
float GetGreen(void) const
Definition: rgba_color.hpp:321
double f(double x_, const double &y_)
Definition: njn_root.hpp:188
Definition: type.c:8
CGlRect reprsents rectangle in the coordinate system with origin located in the left bottom corner...
Definition: glrect.hpp:51
void SetLightColor(const CRgbaColor &c)
T Bottom() const
Definition: glrect.hpp:82
void SetBlue(float r)
Definition: rgba_color.cpp:281
const float * GetColorArray(void) const
Access the color array directly.
Definition: rgba_color.hpp:388
CRgbaColor m_LightColor
void SetDarkColor(void)
float GetBlue(void) const
Definition: rgba_color.hpp:327
T Height() const
Definition: glrect.hpp:90
class CRgbaColor provides a simple abstraction for managing colors.
Definition: rgba_color.hpp:57
CRgbaColor m_DarkColor
void SetRed(float r)
Set specific channels from floating point values.
Definition: rgba_color.cpp:269
void SetType(EType type)
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:98
CRef< CGlTexture > m_Texture
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:768
Modified on Thu Dec 14 18:08:50 2017 by modify_doxy.py rev. 546573