Code: Select all
//RTT Alpha Test for Irrlicht
#include <irrlicht.h>
class InputManager : public irr::IEventReceiver
{
public:
bool renderToRtt;
InputManager() : renderToRtt(true) {}
virtual bool OnEvent(const irr::SEvent& event)
{
if (event.EventType==irr::EET_KEY_INPUT_EVENT && event.KeyInput.Key==irr::KEY_KEY_R) {renderToRtt = !event.KeyInput.PressedDown;}
return false;
}
};
int main(int argc,char* argv[])
{
InputManager* input = new InputManager();
irr::IrrlichtDevice* device = irr::createDevice(irr::video::EDT_DIRECT3D9,irr::core::dimension2du(512,512),32,false,false,false,input);
irr::video::IVideoDriver* driver = device->getVideoDriver();
irr::video::ITexture* rtt = driver->addRenderTargetTexture(driver->getScreenSize(),"rt",irr::video::ECF_A8R8G8B8);
irr::video::ITexture* bg = driver->getTexture("pattern.png");
irr::video::ITexture* one = driver->getTexture("redfade.png");
irr::video::ITexture* two = driver->getTexture("bluefade.png");
//Make the screen mesh
irr::scene::SMeshBuffer screenMesh;
screenMesh.Vertices.set_used(4);
screenMesh.Indices.set_used(6);
screenMesh.Vertices[0]=irr::video::S3DVertex(-1.f,-1.f,0.f,0.f,0.f,1.f,irr::video::SColor(255,255,255,255),0.f,1.f);//Bottom Left
screenMesh.Vertices[1]=irr::video::S3DVertex(-1.f, 1.f,0.f,0.f,0.f,1.f,irr::video::SColor(255,255,255,255),0.f,0.f);//Top Left
screenMesh.Vertices[2]=irr::video::S3DVertex( 1.f, 1.f,0.f,0.f,0.f,1.f,irr::video::SColor(255,255,255,255),1.f,0.f);//Top Right
screenMesh.Vertices[3]=irr::video::S3DVertex( 1.f,-1.f,0.f,0.f,0.f,1.f,irr::video::SColor(255,255,255,255),1.f,1.f);//Bottom Right
screenMesh.Indices[0]=0;
screenMesh.Indices[1]=1;
screenMesh.Indices[2]=2;
screenMesh.Indices[3]=2;
screenMesh.Indices[4]=3;
screenMesh.Indices[5]=0;
//-----------------------------
while(device->run())
{
driver->beginScene(true,true,irr::video::SColor(255,255,0,255));
driver->draw2DImage(bg,irr::core::vector2di(0,0));
if (input->renderToRtt) {driver->setRenderTarget(rtt);}
driver->draw2DImage(two,irr::core::vector2di(150,115) ,irr::core::recti(0,0,250,100),0,irr::video::SColor(255,255,255,255),true);
driver->draw2DImage(one,irr::core::vector2di(300,100),irr::core::recti(0,0,100,250),0,irr::video::SColor(255,255,255,255),true);
if (input->renderToRtt)
{
driver->setRenderTarget(0,false,false);
//Draw the RTT on the screen:
irr::core::recti oldViewport = driver->getViewPort();
irr::core::matrix4 oldViewMat = driver->getTransform(irr::video::ETS_VIEW);
irr::core::matrix4 oldProjMat = driver->getTransform(irr::video::ETS_PROJECTION);
driver->setViewPort(irr::core::recti(irr::core::vector2di(0,0),(irr::core::dimension2di)driver->getScreenSize()));
driver->setTransform(irr::video::ETS_VIEW,irr::core::matrix4());
driver->setTransform(irr::video::ETS_PROJECTION,irr::core::matrix4());
driver->setTransform(irr::video::ETS_WORLD,irr::core::matrix4());
irr::video::SMaterial mat;
mat.BackfaceCulling=true;
mat.Lighting=false;
mat.MaterialType=irr::video::EMT_TRANSPARENT_ALPHA_CHANNEL;
mat.TextureLayer[0].Texture=rtt;
mat.TextureLayer[0].TextureWrapU=irr::video::ETC_CLAMP_TO_EDGE;
mat.TextureLayer[0].TextureWrapV=irr::video::ETC_CLAMP_TO_EDGE;
mat.TextureLayer[0].BilinearFilter=false;
driver->setMaterial(mat);
driver->drawMeshBuffer(&screenMesh);
driver->setViewPort(oldViewport);
driver->setTransform(irr::video::ETS_VIEW,oldViewMat);
driver->setTransform(irr::video::ETS_PROJECTION,oldProjMat);
}
driver->endScene();
}
device->drop();
return 0;
}
EDIT: I was playing around with the source for the DirectX and OpenGL setRenderStates2DMode functions, I got some amusing results but nothing desirable. (I messed around with like 2830 of COpenGLDriver.cpp the most)