Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
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
00083
00084
00085
00086
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 }