screen_rect.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2010, Willow Garage, Inc.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Neither the name of the Willow Garage, Inc. nor the names of its
00014  *       contributors may be used to endorse or promote products derived from
00015  *       this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00030 #include <rve_render_server/screen_rect.h>
00031 #include <rve_render_server/render_target.h>
00032 #include <rve_render_server/renderer.h>
00033 
00034 #include <OGRE/OgreRectangle2D.h>
00035 #include <OGRE/OgreMaterial.h>
00036 #include <OGRE/OgreMaterialManager.h>
00037 #include <OGRE/OgreTexture.h>
00038 #include <OGRE/OgreTextureUnitState.h>
00039 #include <OGRE/OgrePass.h>
00040 #include <OGRE/OgreTechnique.h>
00041 
00042 namespace rve_render_server
00043 {
00044 
00045 class ScreenRectRenderable : public Ogre::Rectangle2D
00046 {
00047 public:
00048   ScreenRectRenderable()
00049   : Ogre::Rectangle2D(true)
00050   {
00051     std::stringstream ss;
00052     static uint32_t count = 0;
00053     ss << "ScreenRectMaterial" << count++;
00054     mat = Ogre::MaterialManager::getSingleton().create(ss.str(), ROS_PACKAGE_NAME);
00055     mat->setLightingEnabled(false);
00056     mat->setDepthCheckEnabled(false);
00057     mat->setDepthWriteEnabled(true);
00058     setMaterial(mat->getName());
00059   }
00060 
00061   ~ScreenRectRenderable()
00062   {
00063     Ogre::MaterialManager::getSingleton().remove(mat->getName());
00064   }
00065 
00066   Ogre::MaterialPtr mat;
00067 };
00068 
00069 ScreenRect::ScreenRect(const rve_common::UUID& id)
00070 : id_(id)
00071 {
00072   renderable_ = new ScreenRectRenderable();
00073 }
00074 
00075 ScreenRect::~ScreenRect()
00076 {
00077   delete renderable_;
00078 }
00079 
00080 void ScreenRect::setCorners(float x0, float y0, float x1, float y1)
00081 {
00082   // Ogre wants these in:
00083   //left    Left position in screen relative coordinates, -1 = left edge, 1.0 = right edge
00084   //top     Top position in screen relative coordinates, 1 = top edge, -1 = bottom edge
00085   //right   Right position in screen relative coordinates
00086   //bottom  Bottom position in screen relative coordinates
00087 
00088   renderable_->setCorners(x0 * 2.0 - 1.0, 1.0 - (y0 * 2.0), x1 * 2.0 - 1.0, 1.0 - y1 * 2.0);
00089 }
00090 
00091 void ScreenRect::setColor(const Ogre::ColourValue& color)
00092 {
00093   Ogre::Pass* p = renderable_->mat->getTechnique(0)->getPass(0);
00094   p->removeAllTextureUnitStates();
00095   p->setDiffuse(color);
00096 }
00097 
00098 void ScreenRect::setTexture(const std::string& ogre_texture_name)
00099 {
00100   Ogre::Pass* p = renderable_->mat->getTechnique(0)->getPass(0);
00101   if (p->getNumTextureUnitStates() == 0)
00102   {
00103     p->createTextureUnitState();
00104   }
00105 
00106   Ogre::TextureUnitState* tu = p->getTextureUnitState(0);
00107   tu->setTextureName(ogre_texture_name);
00108 }
00109 
00110 void ScreenRect::setZOrder(uint32_t zorder)
00111 {
00112   zorder_ = zorder;
00113 }
00114 
00115 Ogre::Renderable* ScreenRect::getRenderable()
00116 {
00117   return renderable_;
00118 }
00119 
00120 }


rve_render_server
Author(s): Josh Faust
autogenerated on Wed Dec 11 2013 14:31:15