<!-- Wanted to avoid copying .css to each folder, so copied default .css from doxyen in here, kicked out most stuff we don't need for examples and modified some a little bit.
Target was having a single html in each example folder which is created from the main.cpp files and needs no files besides some images below media folder.
<p>This tutorial shows how to render to a texture using Irrlicht. Render to texture is a feature where everything which would usually be rendered to the screen is instead written to a (special) texture. This can be used to create nice special effects. In addition, this tutorial shows how to enable specular highlights.</p>
<p>In the beginning, everything as usual. Include the needed headers, ask the user for the rendering driver, create the Irrlicht device: </p><divclass="fragment"><divclass="line"><spanclass="preprocessor">#include <irrlicht.h></span></div><divclass="line"><spanclass="preprocessor">#include "driverChoice.h"</span></div><divclass="line"><spanclass="preprocessor">#include "exampleHelper.h"</span></div><divclass="line"></div><divclass="line"><spanclass="keyword">using namespace </span>irr;</div><divclass="line"></div><divclass="line"><spanclass="preprocessor">#ifdef _MSC_VER</span></div><divclass="line"><spanclass="preprocessor">#pragma comment(lib, "Irrlicht.lib")</span></div><divclass="line"><spanclass="preprocessor">#endif</span></div><divclass="line"></div><divclass="line"><spanclass="keywordtype">int</span> main()</div><divclass="line">{</div><divclass="line"><spanclass="comment">// ask user for driver</span></div><divclass="line"> video::E_DRIVER_TYPE driverType=driverChoiceConsole();</div><divclass="line"><spanclass="keywordflow">if</span> (driverType==video::EDT_COUNT)</div><divclass="line"><spanclass="keywordflow">return</span> 1;</div><divclass="line"></div><divclass="line"><spanclass="comment">// create device and exit if creation failed</span></div><divclass="line"></div><divclass="line"> IrrlichtDevice *device =</div><divclass="line"> createDevice(driverType, core::dimension2d<u32>(640, 480),</div><divclass="line"> 16, <spanclass="keyword">false</span>, <spanclass="keyword">false</span>);</div><divclass="line"></div><divclass="line"><spanclass="keywordflow">if</span> (device == 0)</div><divclass="line"><spanclass="keywordflow">return</span> 1; <spanclass="comment">// could not create selected driver.</span></div><divclass="line"></div><divclass="line"> video::IVideoDriver* driver = device->getVideoDriver();</div><divclass="line"> scene::ISceneManager* smgr = device->getSceneManager();</div><divclass="line"> gui::IGUIEnvironment* env = device->getGUIEnvironment();</div><divclass="line"></div><divclass="line"><spanclass="keyword">const</span> io::path mediaPath = getExampleMediaPath();</div></div><!-- fragment --><p> Now, we load an animated mesh to be displayed. As in most examples, we'll take the fairy md2 model. The difference here: We set the shininess of the model to a value other than 0 which is the default value. This enables specular highlights on the model if dynamic lighting is on. The value influences the size of the highlights. </p><divclass="fragment"><divclass="line"><spanclass="comment">// load and display animated fairy mesh</span></div><divclass="line"></div><divclass="line">scene::IAnimatedMeshSceneNode* fairy = smgr->addAnimatedMeshSceneNode(</div><divclass="line"> smgr->getMesh(mediaPath + <spanclass="stringliteral">"faerie.md2"</span>));</div><divclass="line"></div><divclass="line"><spanclass="keywordflow">if</span> (fairy)</div><divclass="line">{</div><divclass="line"> fairy->setMaterialTexture(0,</div><divclass="line"> driver->getTexture(mediaPath + <spanclass="stringliteral">"faerie2.bmp"</span>)); <spanclass="comment">// set diffuse texture</span></div><divclass="line"> fairy->setMaterialFlag(video::EMF_LIGHTING, <spanclass="keyword">true</span>); <spanclass="comment">// enable dynamic lighting</span></div><divclass="line"> fairy->getMaterial(0).Shininess = 20.0f; <spanclass="comment">// set size of specular highlights</span></div><divclass="line"> fairy->setPosition(core::vector3df(-10,0,-100));</div><divclass="line"> fairy->setMD2Animation ( scene::EMAT_STAND );</div><divclass="line">}</div></div><!-- fragment --><p> To make specular highlights appear on the model, we need a dynamic light in the scene. We add one directly in vicinity of the model. In addition, to make the model not that dark, we set the ambient light to gray. </p
<p>(Note: If you worked with older Irrlicht versions (before 1.9) you might be used to only create a rendertarget texture and no explicit rendertarget. While that's still possible, it's no longer recommended.)</p>
<p>The rendertarget textures are not like standard textures, but need to be created first. To create them, we call IVideoDriver::addRenderTargetTexture() and specify the size of the texture and the type. For depth-maps you can use types ECF_D16, ECF_D32 or ECF_D24S8. When ECF_D24S8 you can also use a stencil-buffer.</p>
<p>Because we want to render the scene not from the user camera into the texture, we add another fixed camera to the scene. But before we do all this, we check if the current running driver is able to render to textures. If it is not, we simply display a warning text. </p><divclass="fragment"><divclass="line"><spanclass="comment">// create render target</span></div><divclass="line">video::IRenderTarget* renderTarget = 0;</div><divclass="line">scene::ICameraSceneNode* fixedCam = 0;</div><divclass="line"></div><divclass="line"><spanclass="keywordflow">if</span> (driver->queryFeature(video::EVDF_RENDER_TO_TARGET))</div><divclass="line">{</div><divclass="line"><spanclass="keyword">const</span> core::dimension2d<u32> rtDim(256, 256); <spanclass="comment">// always use same size for render target texture and it's depth-buffer</span></div><divclass="line"> video::ITexture* renderTargetTex = driver->addRenderTargetTexture(rtDim, <spanclass="stringliteral">"RTT1"</span>, video::ECF_A8R8G8B8);</div><divclass="line"> video::ITexture* renderTargetDepth = driver->addRenderTargetTexture(rtDim, <spanclass="stringliteral">"DepthStencil"</span>, video::ECF_D16); </div><divclass="line"></div><divclass="line"> renderTarget = driver->addRenderTarget();</div><divclass="line"> renderTarget->setTexture(renderTargetTex, renderTargetDepth);</div><divclass="line"></div><divclass="line"> cube->setMaterialTexture(0, renderTargetTex); <spanclass="comment">// set material of cube to render target</span></div><divclass="line"></div><divclass="line"><spanclass="comment">// add fixed camera</span></div><divclass="line"> fixedCam = smgr->addCameraSceneNode(0, core::vector3df(10,10,-80),</div><divclass="line"> core::vector3df(-10,10,-100));</div><divclass="line">}</div><divclass="line"><spanclass="keywordflow">else</span></div><divclass="line">{</div><divclass="line"><spanclass="comment">// create problem text</span></div><divclass="line"> gui::IGUISkin* skin = env->getSkin();</div><divclass="line"> gui::IGUIFont* font = env->getFont(mediaPath + <spanclass="stringliteral">"fonthaettenschweiler.bmp"</span>);</div><divclass="line"><spanclass="keywordflow">if</span> (font)</div><divclass="line"> skin->setFont(font);</div><divclass="line"></div><divclass="line"> gui::IGUIStaticText* text = env->addStaticText(</div><divclass="line"> L<spanclass="stringliteral">"Your hardware or this renderer is not able to use the "</span>\</div><divclass="line"> L<spanclass="stringliteral">"render to texture feature. RTT Disabled."</span>,</div><divclass="line"> core::rect<s32>(150,20,470,60));</div><divclass="line"></div><divclass="line"> text->setOverrideColor(video::SColor(100,255,255,255));</div><divclass="line">}</div><divclass="line"></div><divclass="line"><spanclass="comment">// add fps camera</span></div><divclass="line">scene::ICameraSceneNode* fpsCamera = smgr->addCameraSceneNodeFPS();</div><divclass="line">fpsCamera->setPosition(core::vector3df(-50,50,-150));</div><divclass="line"></div><divclass="line"><spanclass="comment">// disable mouse cursor</span></div><divclass="line">device->getCursorControl()->setVisible(<spanclass="keyword">false</span>);</div></div><!-- fragment --><p> Nearly finished. Now we need to draw everything. Every frame, we draw the scene twice. Once from the fixed camera into the render target texture and once as usual. When rendering into the render target, we need to disable the visibility of the test cube, because it has the render target texture applied to it. That's it, wasn't too complicated I hope. :) </p><divclass="fragment"><divclass="line"><spanclass="keywordtype">int</span> lastFPS = -1;</div><divclass="line"></div><divclass="line"><spanclass="keywordflow">while</span>(device->run())</div><divclass="line"><spanclass="keywordflow">if</span> (device->isWind