I have a beginner's problem with transparency. The core of my problem is shown on following three figures:
On the first one, there is a green box (center) between a camera (on right side) and some blue object (left side).
The second one shows a look on the blue object from that camera.
And, finally, the third one depicts the thing I need - to get a look from camera like if the green cube and everything after that cube is transparent, so I can see the visible contour of blue objects, and the rest of its parts, hidden after green box, are transparent.
I know at least three ways of how to achieve this. First is something about z-buffer priority in opengl, second is ray tracing and the last one is to mix two textures. The last one seems less complicated to me, so I tried to use that:
I've drawn a scene to texture, mix it with the background texture and draw the resulting texture. The code I used looks like this:
Code: Select all
void drawVideoTextureMix(irr::video::ITexture* rt){
s32* rtData = (s32*)rt->lock();
s32* ctData = (s32*)CurrentTexture->lock(true);
irr::video::SColor transparent(255,0,0,0);
IImage * rtImage = IrrVideoDriver->createImageFromData(rt->getColorFormat(), rt->getSize(), rtData, false);
int pixelCount = rt->getSize().Width*rt->getSize().Height;
int i = 0;
for (int h = 0; h < rt->getSize().Height; h++){
for (int w = 0; w < rt->getSize().Width; w++){
SColor pixel = rtImage->getPixel(w,h);
if (pixel == transparent){
rtData[i] = ctData[i];
}
i++;
}
}
rt->unlock();
CurrentTexture->unlock();
IrrVideoDriver->draw2DImage(rt, irr::core::position2d<irr::s32>(0,0),
irr::core::rect<irr::s32>(0,0,desiredW,desiredH), 0, irr::video::SColor(255,255,255,255), false);
}