you know ~ Alpha transparency ?
how can i set the Material's setting...
/// my source...
#include <irrlicht.h>
#include <iostream>
using namespace irr;
#pragma comment(lib, "Irrlicht.lib")
class CSampleSceneNode : public scene::ISceneNode
{
core::aabbox3d<f32> Box;
video::S3DVertex Vertices[6];
video::SMaterial Material;
public:
CSampleSceneNode(scene::ISceneNode* parent, scene::ISceneManager* mgr, s32 id)
: scene::ISceneNode(parent, mgr, id)
{
video::IVideoDriver* driver = SceneManager->getVideoDriver();
Material.Wireframe = false;
Material.Lighting = false;
Material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
//EMT_TRANSPARENT_ALPHA_CHANNEL
//EMT_TRANSPARENT_ADD_COLOR
Material.Textures[0] = driver->getTexture("Fire03.bmp");
s32 al = 255;
Vertices[0] = video::S3DVertex(-400,300,0, 1,1,0, video::SColor(al,255,255,255), 0, 0);
Vertices[1] = video::S3DVertex(400,-300,0, 1,0,0, video::SColor(al,255,255,255), 1, 1);
Vertices[2] = video::S3DVertex(-400,-300,0, 0,1,1, video::SColor(al,255,255,255), 0, 1);
Vertices[3] = video::S3DVertex(-400,300,0, 0,0,1, video::SColor(al,255,255,255), 0, 0);
Vertices[4] = video::S3DVertex(400,300,0, 0,0,1, video::SColor(al,255,255,255), 1, 0);
Vertices[5] = video::S3DVertex(400,-300,0, 0,0,1, video::SColor(al,255,255,255), 1, 1);
Box.reset(Vertices[0].Pos);
for (s32 i=1; i<6; ++i)
Box.addInternalPoint(Vertices.Pos);
}
virtual void OnRegisterSceneNode()
{
if (IsVisible)
SceneManager->registerNodeForRendering(this);
ISceneNode::OnRegisterSceneNode();
}
virtual void render()
{
u16 indices[] = {0,1,2,3,4,5};
video::IVideoDriver* driver = SceneManager->getVideoDriver();
driver->setMaterial(Material);
driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
driver->drawIndexedTriangleList(&Vertices[0], 6, &indices[0], 2);
}
virtual const core::aabbox3d<f32>& getBoundingBox() const
{
return Box;
}
virtual u32 getMaterialCount()
{
return 1;
}
virtual video::SMaterial& getMaterial(u32 i)
{
return Material;
}
};
int main()
{
video::E_DRIVER_TYPE driverType;
IrrlichtDevice *device =
createDevice(video::EDT_DIRECT3D9, core::dimension2d<s32>(800, 600), 16, false);
if (device == 0)
return 1;
device->setWindowCaption(L"Custom Scene Node - Irrlicht Engine Demo");
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
smgr->addCameraSceneNode(0, core::vector3df(0,0,-500), core::vector3df(0,0,0));
CSampleSceneNode *myNode =
new CSampleSceneNode(smgr->getRootSceneNode(), smgr, 666);
myNode->drop();
myNode->setScale(core::vector3df(0.5f,0.5f,0.5f));
scene::ISceneNodeAnimator* anim =
smgr->createRotationAnimator(core::vector3df(0.0f, 0.0f, 1.0f));
//myNode->addAnimator(anim);
anim->drop();
u32 frames=0;
while(device->run())
{
driver->beginScene(true, true, video::SColor(100,0,0,255));
smgr->drawAll();
driver->endScene();
if (++frames==100)
{
core::stringw str = L"Irrlicht Engine [";
str += driver->getName();
str += L"] FPS: ";
str += (s32)driver->getFPS();
device->setWindowCaption(str.c_str());
frames=0;
}
}
device->drop();
return 0;
}
Alpha transparency ~ help me
As discussed over messenger, if you are going to attempt to use the material type video::EMT_TRANSPARENT_ALPHA_CHANNEL, you need to use a texture that has an alpha channel. The most common BITMAP formats don't support an alpha channel. The normal 24-bit format only has RGB color information. Unless you are using 32-bpp bitmaps, the result won't be like you want. The TARGA format supports an alpha channel, all you have to do is use it. As an example...
Travis
Code: Select all
Material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
Material.Textures[0] = driver->getTexture("../../media/irrlichtlogoalpha2.tga");
Travis~ Success~ But
i Sucess ~ AlphaBlending...
but .. if i change the Alpha Value 100 .. it is not transparency..
Like this.. (Directx)
g_Device->SetTextureStageState(0,D3DTSS_COLORARG1,D3DTA_TEXTURE);
g_Device->SetTextureStageState(0,D3DTSS_COLORARG2,D3DTA_CURRENT);
g_Device->SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_MODULATE);
g_Device->SetTextureStageState(0,D3DTSS_ALPHAARG1,D3DTA_TEXTURE);
g_Device->SetTextureStageState(0,D3DTSS_ALPHAARG2,D3DTA_CURRENT);
g_Device->SetTextureStageState(0,D3DTSS_ALPHAOP,D3DTOP_SELECTARG1);
g_Device->SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE);
g_Device->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_SRCALPHA);
g_Device->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVSRCALPHA);
.......
but .. if i change the Alpha Value 100 .. it is not transparency..
Like this.. (Directx)
g_Device->SetTextureStageState(0,D3DTSS_COLORARG1,D3DTA_TEXTURE);
g_Device->SetTextureStageState(0,D3DTSS_COLORARG2,D3DTA_CURRENT);
g_Device->SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_MODULATE);
g_Device->SetTextureStageState(0,D3DTSS_ALPHAARG1,D3DTA_TEXTURE);
g_Device->SetTextureStageState(0,D3DTSS_ALPHAARG2,D3DTA_CURRENT);
g_Device->SetTextureStageState(0,D3DTSS_ALPHAOP,D3DTOP_SELECTARG1);
g_Device->SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE);
g_Device->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_SRCALPHA);
g_Device->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVSRCALPHA);
.......