glcanvas.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:8k
- /*
- * ===========================================================================
- * PRODUCTION $Log: glcanvas.cpp,v $
- * PRODUCTION Revision 1000.1 2004/06/01 20:50:30 gouriano
- * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.25
- * PRODUCTION
- * ===========================================================================
- */
- /* $Id: glcanvas.cpp,v 1000.1 2004/06/01 20:50:30 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:
- * CGlCanvas -- provide standardized OpenGL view setup for FLTK
- */
- #include <ncbi_pch.hpp>
- #include <gui/opengl.h>
- #include <gui/opengl/glcanvas.hpp>
- #include <gui/opengl/glprint.hpp>
- #include <gui/opengl/glutils.hpp>
- BEGIN_NCBI_SCOPE
- //
- // hackish work-around to eliminate the default callback that FLTK uses...
- //
- static void s_NullCallback(Fl_Widget*, void*)
- {
- }
- CGlCanvas::CGlCanvas(int x, int y, int width, int height, const char* label)
- : Fl_Gl_Window(x, y, width, height, label),
- m_RenderModes(0),
- m_Capture(false)
- {
- callback(s_NullCallback);
- }
- CGlCanvas::~CGlCanvas(void)
- {
- }
- void CGlCanvas::draw_print(void)
- {
- m_Capture = true;
- draw();
- m_Capture = false;
- }
- void CGlCanvas::draw(void)
- {
- x_SetupView();
- x_Draw();
- if (!m_Capture) {
- x_OverlayDraw();
- }
- CGlUtils::CheckGlError();
- }
- //
- // CGlCanvas::setupRenderModes(void)
- // this function sets a very basic set of render modes
- //
- void CGlCanvas::x_SetupRenderModes(void)
- {
- if (m_RenderModes & fLighting) {
- glEnable(GL_LIGHTING);
- } else {
- glDisable(GL_LIGHTING);
- }
- if (m_RenderModes & fCullFace) {
- glEnable(GL_CULL_FACE);
- } else {
- glDisable(GL_CULL_FACE);
- }
- if (m_RenderModes & fDepthTest) {
- glEnable(GL_DEPTH_TEST);
- } else {
- glDisable(GL_DEPTH_TEST);
- }
- if (m_RenderModes & fTexture2D) {
- glEnable(GL_TEXTURE_2D);
- } else {
- glDisable(GL_TEXTURE_2D);
- }
- }
- void CGlCanvas::x_DrawBackground(float red, float green, float blue)
- {
- glClearColor(red, green, blue, 0);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- }
- void CGlCanvas::Print(const CPrintOptions& opts)
- {
- make_current();
- const unsigned int orig_w = w();
- const unsigned int orig_h = h();
- const CPrintOptions::TOutputFormat fmt = opts.GetOutputFormat();
- if (CPrintOptions::s_IsRasterFormat(fmt)) {
- const unsigned int _w = opts.GetRasterWidth();
- const unsigned int _h = opts.GetRasterHeight();
- size(_w, _h);
- }
- GLPrint(this, &CGlCanvas::draw_print, opts);
- if (CPrintOptions::s_IsRasterFormat(fmt)) {
- size(orig_w, orig_h);
- draw();
- }
- }
- END_NCBI_SCOPE
- /*
- * ===========================================================================
- * $Log: glcanvas.cpp,v $
- * Revision 1000.1 2004/06/01 20:50:30 gouriano
- * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.25
- *
- * Revision 1.25 2004/05/21 22:27:44 gorelenk
- * Added PCH ncbi_pch.hpp
- *
- * Revision 1.24 2003/09/29 15:43:43 dicuccio
- * +glutils.hpp for CGlUtils
- *
- * Revision 1.23 2003/07/21 19:31:34 dicuccio
- * Added NULL callback for CGlCanvas - works around interenting problem with
- * Fl_Gl_Window's default callback. Removed unused ctor.
- *
- * Revision 1.22 2003/07/15 18:53:53 meric
- * Resize the canvas as requested if printing to a raster format
- *
- * Revision 1.21 2003/06/25 16:22:41 meric
- * Moved printing functionality to gui/opengl/gl_print and gui/utils/print
- *
- * Revision 1.20 2003/06/24 22:46:45 meric
- * Temporary fix: added includes to allow MSVC++ to compile error/warning-free.
- * These includes are for printing functionality, which will be moved shortly.
- *
- * Revision 1.19 2003/06/19 16:34:21 meric
- * Pass file type parameter to CAppPopup::PopupFile
- *
- * Revision 1.18 2003/06/19 00:54:58 dicuccio
- * Minor reformatting. Changed LOG_POST() to _TRACE().
- *
- * Revision 1.17 2003/06/18 19:44:40 meric
- * Print: loop to increase size of feedback buffer as necessary
- *
- * Revision 1.16 2003/06/18 17:26:57 meric
- * Final phase of print reorg: print classes now in gui/utils
- *
- * Revision 1.15 2003/06/17 19:34:32 meric
- * Call CAppPopup::PopupFile() instead of CAppPopup::Popup()
- *
- * Revision 1.14 2003/06/17 12:08:42 meric
- * Fixed CVectorOutput to include separate call to SetOutputStream()
- * Remove static keyword from s_Print (anachronism)
- *
- * Revision 1.13 2003/06/16 21:20:31 meric
- * Changed auto_ptr<> to CRef<> on a CObject-derived class (COpenGLPrintBuffer)
- *
- * Revision 1.12 2003/06/16 19:10:59 meric
- * Remove print buffer from print context before the context is destroyed. (this
- * code was 'lost' in the previous update).
- *
- * Revision 1.11 2003/06/16 16:56:10 dicuccio
- * Fix compiler error for MSVC
- *
- * Revision 1.10 2003/06/16 15:59:10 dicuccio
- * Work-in-progress: everything compiles, still much reorganization to be done.
- * Moved generic functionality out of opengl/print/ and into gui/utils (print
- * options, print dialogs, etc.). Removed interactive state from CGlCanvas.
- * Added hook in CView for opening standard print dialog, and for generic print
- * handling. Restored log for glcanvas.cpp
- *
- * Revision 1.9 2003/06/13 18:44:04 meric
- * Initialization in x_Init(), which is called by all c'tors
- * Remove print-related functinality from draw(), which can now be
- * overridden freely without affecting the Print() function.
- * Add print functions [ Print(), x_Print() etc ]
- *
- * Revision 1.8 2003/05/22 15:51:06 meric
- * small changes to GL Feedback code (remains commented out)
- *
- * Revision 1.7 2003/05/13 19:25:20 dicuccio
- * Prepare CGlCanvas for printing support (Peter Meric)
- *
- * Revision 1.6 2003/05/06 15:59:44 dicuccio
- * Split CGlCanvas into 2D and 3D versions; moved hardware check into CGlUtils
- *
- * Revision 1.5 2003/03/28 17:16:01 dicuccio
- * Added first support for testing for hardware acceleration
- *
- * Revision 1.4 2003/01/13 13:10:11 dicuccio
- * Namespace clean-up. Retired namespace gui -> converted all to namespace
- * ncbi. Moved all FLUID-generated code into namespace ncbi.
- *
- * Revision 1.3 2002/11/14 16:24:44 dicuccio
- * Changed to include standard OpenGL headers through 'gui/opengl.h'
- *
- * Revision 1.2 2002/11/08 13:27:45 dicuccio
- * Code clean-up and reformatting.
- *
- * Revision 1.1 2002/11/05 20:21:47 dicuccio
- * Initial revision
- *
- * ===========================================================================
- */