UnitText.h

00001 /***************************************************************************
00002  *   Copyright (c) 2008   Art Tevs                                         *
00003  *                                                                         *
00004  *   This library is free software; you can redistribute it and/or modify  *
00005  *   it under the terms of the GNU Lesser General Public License as        *
00006  *   published by the Free Software Foundation; either version 3 of        *
00007  *   the License, or (at your option) any later version.                   *
00008  *                                                                         *
00009  *   This library is distributed in the hope that it will be useful,       *
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00012  *   GNU Lesse General Public License for more details.                    *
00013  *                                                                         *
00014  *   The full license is in LICENSE file included with this distribution.  *
00015  ***************************************************************************/
00016 
00017 #ifndef _C_UNITS_TEXT_HUD_H_
00018 #define _C_UNITS_TEXT_HUD_H_
00019 
00020 
00021 //-------------------------------------------------------------------------
00022 // Includes
00023 //-------------------------------------------------------------------------
00024 #include <osgText/Text>
00025 
00026 #include <osgPPU/Export.h>
00027 #include <osgPPU/UnitInOut.h>
00028 
00029 namespace osgPPU
00030 {
00031     //! Same as UnitInOut but renders text onto the output.
00032     /**
00033     * The text is displayed in 2D ortho mode. This class is wrapper for the 
00034     * osgText::Text class, so check it for more information about the text support.
00035     **/
00036     class OSGPPU_EXPORT UnitText : public UnitInOut
00037     {
00038         public:
00039             META_Node(osgPPU, UnitText);
00040 
00041             //! Create default ppfx 
00042             UnitText();
00043             UnitText(const UnitText&, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
00044             
00045             //! Release it and used memory
00046             virtual ~UnitText();
00047             
00048             //! Initialze the default postprocessing unit 
00049             virtual void init();
00050         
00051             //! Set size of the characters (relative to viewport.width / 640)
00052             inline void setSize(float size)
00053             {
00054                 mSize= size;
00055                 if (getViewport())
00056                     mText->setCharacterSize(mSize * (float(getViewport()->width()) / 640.0), 1.0);
00057             }
00058             inline float getSize() const { return mSize; }
00059 
00060             //! Set text position in 2D coordinates        
00061             inline void setPosition(float x, float y) { mText->setPosition(osg::Vec3(x,y,0)); }
00062 
00063             //! Text Unit does work as a simple bypass, hence return here always the input
00064             inline osg::Texture* getOrCreateOutputTexture(int mrt = 0) { return mInputTex[mrt].get(); }
00065 
00066             //! Get text assigned with this unit
00067             osgText::Text& getText() { return *mText; }
00068             const osgText::Text& getText() const { return *mText; }
00069 
00070             //! Set string drawed by the text
00071             void setText(const std::string& txt) { mText->setText(txt); }
00072 
00073             //! Set the text pointer used for the rendering
00074             void setText(osgText::Text* text);
00075 
00076         protected:
00077 
00078             //! Text class holder
00079             osg::ref_ptr<osgText::Text> mText;
00080 
00081             //! Size of the font
00082             float mSize;
00083 
00084             virtual bool noticeBeginRendering (osg::RenderInfo&, const osg::Drawable* ) ;
00085 
00086 
00087     };
00088 
00089 }; // end namespace
00090 
00091 #endif

Back to Homepage of osgPPU

Copyright (C) 2008 by Art Tevs (LGPL)