glbackground.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:6k
- /*
- * ===========================================================================
- * PRODUCTION $Log: glbackground.cpp,v $
- * PRODUCTION Revision 1000.2 2004/06/01 20:50:23 gouriano
- * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.3
- * PRODUCTION
- * ===========================================================================
- */
- /* $Id: glbackground.cpp,v 1000.2 2004/06/01 20:50:23 gouriano Exp $
- * ===========================================================================
- *
- * PUBLIC DOMAIN NOTICE
- * National Center for Biotechnology Information
- *
- * This software/database is a "United States Government Work" under the
- * terms of the United States Copyright Act. It was written as part of
- * the author's official duties as a United States Government employee and
- * thus cannot be copyrighted. This software/database is freely available
- * to the public for use. The National Library of Medicine and the U.S.
- * Government have not placed any restriction on its use or reproduction.
- *
- * Although all reasonable efforts have been taken to ensure the accuracy
- * and reliability of the software and data, the NLM and the U.S.
- * Government do not and cannot warrant the performance or results that
- * may be obtained by using this software or data. The NLM and the U.S.
- * Government disclaim all warranties, express or implied, including
- * warranties of performance, merchantability or fitness for any particular
- * purpose.
- *
- * Please cite the author in any work or product based on this material.
- *
- * ===========================================================================
- *
- * Authors: Mike DiCuccio
- *
- * File Description:
- *
- */
- #include <ncbi_pch.hpp>
- #include <gui/opengl/glbackground.hpp>
- BEGIN_NCBI_SCOPE
- CGlBackground::CGlBackground()
- : m_Type(eSolid),
- m_LightColor(1.0f, 1.0f, 1.0f, 1.0f),
- m_DarkColor(1.0f, 1.0f, 1.0f, 1.0f)
- {
- }
- void CGlBackground::SetType(EType type)
- {
- m_Type = type;
- }
- void CGlBackground::SetTexture(CTexImage& image)
- {
- m_Texture.Reset(&image);
- }
- void CGlBackground::SetColor(const CGlColor& c)
- {
- SetLightColor(c);
- }
- void CGlBackground::SetLightColor(const CGlColor& c)
- {
- m_LightColor = c;
- }
- void CGlBackground::SetDarkColor(const CGlColor& c)
- {
- m_DarkColor = c;
- }
- void CGlBackground::SetDarkColor(void)
- {
- // we set the dark color as a fraction of the light color
- m_DarkColor.SetRed(m_LightColor.GetRed() * 0.5f);
- m_DarkColor.SetGreen(m_LightColor.GetGreen() * 0.5f);
- m_DarkColor.SetBlue(m_LightColor.GetBlue() * 0.5f);
- // this doesn't apply to the alpha!
- m_DarkColor.SetAlpha(m_LightColor.GetAlpha());
- }
- void CGlBackground::Draw(const CGlRect<int>& vp)
- {
- glPushAttrib(GL_VIEWPORT_BIT);
- glViewport(vp.Left(), vp.Bottom(), vp.Width(), vp.Height());
- Draw();
- glPopAttrib();
- }
- void CGlBackground::Draw(void)
- {
- //
- // matrix set-up
- // we use an orthographic view, and save all matrices
- //
- glMatrixMode(GL_PROJECTION);
- glPushMatrix();
- glLoadIdentity();
- glOrtho(-1, 1, -1, 1, -1, 1);
- glMatrixMode(GL_MODELVIEW);
- glPushMatrix();
- glLoadIdentity();
- // we also save the enables, as we plan to enable/disable a lot of things
- glPushAttrib(GL_ENABLE_BIT);
- // disable the expensive tests
- glDisable(GL_CULL_FACE);
- glDisable(GL_DEPTH_TEST);
- glDisable(GL_BLEND);
- switch (m_Type) {
- case eSolid:
- // solid background
- // we use only m_LightColor here
- glDisable(GL_TEXTURE_2D);
- glColor3fv(m_LightColor.GetGlColor());
- glBegin(GL_QUADS);
- glVertex2i( 1, -1);
- glVertex2i( 1, 1);
- glVertex2i(-1, 1);
- glVertex2i(-1, -1);
- glEnd();
- break;
- case eGradientDown:
- // gradient from top->bottom, light->dark
- // there is no requirement that light be brighter than dark
- glDisable(GL_TEXTURE_2D);
- glBegin(GL_QUADS);
- glColor3fv(m_LightColor.GetGlColor());
- glVertex2i(-1, 1);
- glVertex2i( 1, 1);
- glColor3fv(m_DarkColor.GetGlColor());
- glVertex2i( 1, -1);
- glVertex2i(-1, -1);
- glEnd();
- break;
- case eGradientRight:
- // gradient from top->bottom, light->dark
- // there is no requirement that light be brighter than dark
- glDisable(GL_TEXTURE_2D);
- glBegin(GL_QUADS);
- glColor3fv(m_LightColor.GetGlColor());
- glVertex2i(-1, 1);
- glVertex2i(-1, -1);
- glColor3fv(m_DarkColor.GetGlColor());
- glVertex2i( 1, -1);
- glVertex2i( 1, 1);
- glEnd();
- break;
- case eTexture:
- // use a texture, if possible. Otherwise, this is the same as a solid
- // background
- // make our texture current if it is available
- if (m_Texture) {
- glEnable(GL_TEXTURE_2D);
- m_Texture->MakeCurrent();
- // this is always rendered with a white background
- glColor3f(1.0f, 1.0f, 1.0f);
- } else {
- glDisable(GL_TEXTURE_2D);
- glColor3fv(m_LightColor.GetGlColor());
- }
- glBegin(GL_QUADS);
- glTexCoord2f(0.0f, 0.0f);
- glVertex2i(-1, 1);
- glTexCoord2f(1.0f, 0.0f);
- glVertex2i( 1, 1);
- glTexCoord2f(1.0f, 1.0f);
- glVertex2i( 1, -1);
- glTexCoord2f(0.0f, 1.0f);
- glVertex2i(-1, -1);
- glEnd();
- break;
- }
- //
- // restore our states
- // this is done so as to leave the modelview matrix as the last active
- // matrix
- //
- glPopAttrib();
- glMatrixMode (GL_PROJECTION);
- glPopMatrix();
- glMatrixMode (GL_MODELVIEW);
- glPopMatrix();
- }
- END_NCBI_SCOPE
- /*
- * ===========================================================================
- * $Log: glbackground.cpp,v $
- * Revision 1000.2 2004/06/01 20:50:23 gouriano
- * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.3
- *
- * Revision 1.3 2004/05/21 22:27:44 gorelenk
- * Added PCH ncbi_pch.hpp
- *
- * Revision 1.2 2004/03/22 18:49:59 dicuccio
- * Added API to restrict drawing to an indicated viewport
- *
- * Revision 1.1 2003/06/09 19:22:13 dicuccio
- * Initial revision
- *
- * ===========================================================================
- */