my problem best i can.
I´m rendering all stuff to a ARGB texture using DirectX device:
Code: Select all
//note i create a 1x1 window, cause all that i want is use the rendered texture in
//other application... so i dont need to see irrlicht window in any moment.
device = createDevice(EDT_DIRECT3D9, dimension2d<u32>(1, 1), 16, false, false, true);
driver = device->getVideoDriver();
smgr = device->getSceneManager();
rt = driver->addRenderTargetTexture(core::dimension2d<u32>(1920,1080), "RTT1", irr::video::ECF_A8R8G8B8);
t1 = driver->getTexture("test1.png");
t2 = driver->getTexture("test3.png");
t3 = driver->getTexture("hello.png");
d1 = GetTickCount();
Code: Select all
void draw()
{
video::S3DVertex vertices[4];
vertices[0].TCoords = core::vector2df(0.0f, 0.0f);
vertices[0].Pos = core::vector3df(10,0,0);
vertices[1].TCoords = core::vector2df(1.0f, 0.0f);
vertices[1].Pos = core::vector3df(1920,0,0);
vertices[2].TCoords = core::vector2df(1.0f, 1.0f);
vertices[2].Pos = core::vector3df(1920,1080,0);
vertices[3].TCoords = core::vector2df(0.0f, 1.0f);
vertices[3].Pos = core::vector3df(10,1080,0);
short int index[4];
for(unsigned int i=0; i<4; i++)
{
index[i]=i;
vertices[i].Color = video::SColor(255, 255, 255, 255);
}
video::SMaterial m;
m.setTexture(0, t1);
m.MaterialType = EMT_TRANSPARENT_ALPHA_CHANNEL;
driver->setMaterial(m);
driver->draw2DVertexPrimitiveList(vertices, 4, index, 4-2, video::EVT_STANDARD, scene::EPT_TRIANGLE_FAN);
}
So, if a open generated file with gimp(for example) i got this:
Ok, everything is fine until now. But if i draw the same image again, but using
a color with alpha, the background will have the same alpha value. i know all this
have something with ALPHA BLENDING. But i dont know what to do:
See whats happining when i draw the same image over the first draw, but using
a color with alpha(video::SColor(100, 255, 255, 255)):
i draw the second time with:
Code: Select all
void draw2()
{
video::S3DVertex vertices[4];
vertices[0].TCoords = core::vector2df(0.0f, 0.0f);
vertices[0].Pos = core::vector3df(200,100,0);
vertices[1].TCoords = core::vector2df(1.0f, 0.0f);
vertices[1].Pos = core::vector3df(560,100,0);
vertices[2].TCoords = core::vector2df(1.0f, 1.0f);
vertices[2].Pos = core::vector3df(560,260,0);
vertices[3].TCoords = core::vector2df(0.0f, 1.0f);
vertices[3].Pos = core::vector3df(200,260,0);
short int index[4];
for(unsigned int i=0; i<4; i++)
{
index[i]=i;
//this alpha(100) should alter only this draw, and not the render
//target background
vertices[i].Color = video::SColor(100, 255, 255, 255);
}
video::SMaterial m;
m.setTexture(0, t1);
m.MaterialType = EMT_ONETEXTURE_BLEND;
m.MaterialTypeParam = pack_texureBlendFunc(video::EBF_DST_ALPHA, video::EBF_ONE_MINUS_SRC_ALPHA, video::EMFN_MODULATE_1X, video::EAS_TEXTURE | video::EAS_VERTEX_COLOR);
m.ZWriteEnable = false;
driver->setMaterial(m);
driver->draw2DVertexPrimitiveList(vertices, 4, index, 4-2, video::EVT_STANDARD, scene::EPT_TRIANGLE_FAN);
}
and i was expecting this:
The main Loop is:
Code: Select all
while(device->run())
{
driver->beginScene(true, true, video::SColor(0,255,255,255));
// set render target texture
driver->setRenderTarget(rt, true, true, video::SColor(0,255,255,255));
// draw whole scene into render buffer
smgr->drawAll();
draw();
draw2();
driver->endScene();
break;
}
char* bits = (char*)rt->lock();
if (bits)
{
//...
Here is the part i save the "rt" texture bits to a file
//...
rt->unlock();
}
I hope somebody can help me.
Thanks anyway.