How to make background transparent?

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
lab_zj
Posts: 26
Joined: Wed May 21, 2008 3:25 am

How to make background transparent?

Post by lab_zj »

I have a big terrain that made up into many triangles, and have a FPS camera used for walk into terrain, and have another camera fixed above terrain used for RTT(render to texture). the RTT has been pasted into screen.

I want to RTT's background is full transparent, so using:
video::IVideoDriver::makeColorKeyTexture(...) and video::draw2DImage(...) to paste to screen. like this:

video::ITexture *m_pRTT=m_pDriver->addRenderTargetTexture(core::dimension2du(512,512),"RTT1",video::ECF_A8R8G8B8);
... ...

while(p_pDevice->run())
{
m_pDriver->setRenderTarget(m_pRTT, true, true, video::SColor(0,0,0,255));
... ...
m_pDriver->makeColorKeyTexture(m_pRTT,video::SColor(0,0,0,255),true);
m_pDriver->draw2DImage(m_pRTT,core::vector2di(1,1),core::recti(0,0,512,512),0,video::SColor(255,255,255,255),true);
}

But when program runs for a while, it automaticly exit, I have traced and found "makeColorKeyTexture" function cause memory's usage quickly increased and result to program exit. Also, the finally RTT texture does not any transparent or full transparent (change last param of draw2DImage function). (The render driver for D3D9 and OpenGL both have this probelm).

So How to process this problem, and sorry for my poor english.

thanks.
Post Reply