Transparent 2d images dont work over a 3d world?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Epsilon
Posts: 38
Joined: Fri Jan 09, 2004 1:46 pm
Location: Argentina

Transparent 2d images dont work over a 3d world?

Post by Epsilon »

Hi, i have readed the tutorial 6 of irrlicht and i have make some test with it.

I want to make an HUD, so i have placed a Q3 map behind of the 2d images (drawing the 3d world first and 2d images at last).

But in the first test, only appears the irrlicht logo, so what is wrong?

i have attempt to fix that so i in the first try i fix the rectangle of the mouse putting the transparancy (alpha) to 255 (opaque).
so, i have tryed the somthing with the demons and the dragons background but nothing happens.

reading i have noticed that in the function of this 2dimages there are a parameters that specifics the pixel black(0,0,0) int the image file is transparent in the engine, so i have changed this to false and works ! but with black background.

not only the transparency is the problem, also the text arent displayed and dont have transparency becouse the alpha is setted to 255.

This problem is not caused by the q3 map, this is caused by the camera that i have placed with the line :
smgr->addCameraSceneNode(0, core::vector3df(0,10,-40), core::vector3df(0,0,0));

All games have HUD transparent so i want to know if i can make it.

thanks.

Sorry for my english.
MedievalMagic13

Post by MedievalMagic13 »

Maybe you should show your source code. It's easier to find the mistakes then.
Tyn
Posts: 932
Joined: Thu Nov 20, 2003 7:53 pm
Location: England
Contact:

Post by Tyn »

I had simular probs a while back, showed the source code and some peeps here seemed to think the source was fine so it would be interesting ( to me ) to see if your code is OK as well. Unfortunatly I never found a way around it and so far I haven't seen anyone else try it, so hopefully someone has a brain wave when they have a go and gets it to work as I'm pretty much bamboozled :(
Epsilon
Posts: 38
Joined: Fri Jan 09, 2004 1:46 pm
Location: Argentina

Post by Epsilon »

is the code of tutorial 6 but with the q3 map of tutorial 2.


#include <irrlicht.h>
using namespace irr;
#pragma comment(lib, "Irrlicht.lib")

int main()
{
IrrlichtDevice *device = createDevice(video::DT_OPENGL,core::dimension2d<s32>(512, 384));
device->setWindowCaption(L"Irrlicht Engine - 2D Graphics Demo");
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();


device->getFileSystem()->addZipFileArchive("map-20kdm2.pk3");
scene::IAnimatedMesh* mesh = smgr->getMesh("20kdm2.bsp");
scene::ISceneNode* node = 0;
if (mesh)
node = smgr->addOctTreeSceneNode(mesh->getMesh(0));
if (node)
node->setPosition(core::vector3df(-1300,-144,-1249));
smgr->addCameraSceneNode(0, core::vector3df(0,10,-40), core::vector3df(0,0,0));


video::ITexture* images = driver->getTexture("2ddemo.bmp");
driver->makeColorKeyTexture(images, core::position2d<s32>(0,0));

gui::IGUIFont* font = device->getGUIEnvironment()->getBuildInFont();
gui::IGUIFont* font2 = device->getGUIEnvironment()->getFont("fonthaettenschweiler.bmp");
core::rect<s32> imp1(349,15,385,78);
core::rect<s32> imp2(387,15,423,78);

while(device->run() && driver)
{
if (device->isWindowActive())
{
u32 time = device->getTimer()->getTime();
driver->beginScene(true, true, video::SColor(0,122,65,171));


smgr->drawAll();


// draw fire & dragons background world
driver->draw2DImage(images, core::position2d<s32>(50,50),core::rect<s32>(0,0,342,224), 0,video::SColor(255,255,255,255), false);
// draw flying imp
driver->draw2DImage(images, core::position2d<s32>(164,125),(time/100 % 2) ? imp1 : imp2, 0, video::SColor(255,255,255,255), false);
// draw second flying imp with colorcylce
driver->draw2DImage(images, core::position2d<s32>(270,105),(time/1000 % 2) ? imp1 : imp2, 0, video::SColor(255,(time) % 255,255,255), false);

// draw some text
if (font)
font->draw(L"This is some text.",core::rect<s32>(130,10,300,50),video::SColor(255,255,255,255));
// draw some other text
if (font2)
font2->draw(L"This is some other text.",core::rect<s32>(130,20,300,60),video::SColor(255,time % 255,time % 255,255));


// draw logo
driver->draw2DImage(images, core::position2d<s32>(10,10),core::rect<s32>(354,87,442,118));

// draw transparent rect under cursor
core::position2d<s32> m = device->getCursorControl()->getPosition();
driver->draw2DRectangle(video::SColor(255,100,100,100),core::rect<s32>(m.X-20, m.Y-20, m.X+20, m.Y+20));

driver->endScene();
}
}

device->drop();
return 0;
}
Last edited by Epsilon on Tue Jan 13, 2004 7:10 pm, edited 1 time in total.
rt
Posts: 150
Joined: Sun Nov 30, 2003 6:54 am
Location: canada
Contact:

Re: Transparent 2d images dont work over a 3d world?

Post by rt »

Epsilon wrote:All games have HUD transparent so i want to know if i can make it.
read this thread http://irrlicht.sourceforge.net/phpBB2/ ... .php?t=517

you can have 8bit transparency but you will have to tweak the irrlicht source code to do it (in 0.4.2)
Epsilon
Posts: 38
Joined: Fri Jan 09, 2004 1:46 pm
Location: Argentina

Post by Epsilon »

that will be implemented in next release?
tstuefe
Posts: 40
Joined: Wed Jan 07, 2004 12:53 pm
Location: Heidelberg, Germany
Contact:

Post by tstuefe »

I was able to get 8bit transparency running (also a HUD with semitransparent elements) using tga textures. You have to edit the TGA alpha channel using a graphics program like paint shop pro.

...thomas
Post Reply