transparent sphere

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
danut007ro
Posts: 16
Joined: Thu Apr 12, 2007 2:21 pm

transparent sphere

Post by danut007ro »

Hello !

I'm trying to make a big sphere that should be transparent (seeing inside it)

This is the code I'm using, but obviously it doesn't work

Code: Select all

#include <irrlicht.h>

using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

#ifdef _IRR_WINDOWS_
#pragma comment(lib, "Irrlicht.lib")
#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")
#endif

int main(int argc, char *argv[])
{
	IrrlichtDevice *device = createDevice(video::EDT_DIRECT3D9, dimension2d<s32>(320, 240), 24, false, true, false, 0);
	if (!device)
		return 1;
	device->setWindowCaption(L"Balls TEST");
	IVideoDriver* driver = device->getVideoDriver();
	ISceneManager* smgr = device->getSceneManager();
	IGUIEnvironment* guienv = device->getGUIEnvironment();
	driver->setTextureCreationFlag(video::ETCF_ALWAYS_32_BIT, true);

	smgr->addLightSceneNode(0, vector3df(0, 0, -60));

	IMeshSceneNode *bowl = smgr->addSphereSceneNode(10, 32);
	if (bowl)
	{
		bowl->setMaterialFlag(EMF_LIGHTING, true);
		bowl->setMaterialFlag(EMF_BACK_FACE_CULLING, true);
		bowl->setMaterialTexture(0, driver->getTexture("white.png"));
		bowl->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR);
	}

	IMeshSceneNode *b1 = smgr->addSphereSceneNode(2, 16);
	if (b1)
	{
		b1->setMaterialFlag(EMF_LIGHTING, false);
		b1->setMaterialTexture(0, driver->getTexture("red.png"));
		bowl->setMaterialType(video::EMT_SOLID);
	}

	smgr->addCameraSceneNodeFPS(0, 100, 0.05);

	while (device->run())
	{
		driver->beginScene(true, true, SColor(255, 0, 0, 0));
		smgr->drawAll();
		guienv->drawAll();
		driver->endScene();
	}

	device->drop();
	return 0;
}
Any help on how to make a transparent sphere, and to set it's transparency level?
Katsankat
Posts: 178
Joined: Sun Mar 12, 2006 4:15 am
Contact:

Post by Katsankat »

Did you notice there is a

Code: Select all

   if (b1) 
   { 
     ...
     bowl->setMaterialType(video::EMT_SOLID); 
  }
If your pngs have no alpha channel, EMT_TRANSPARENT_VERTEX_ALPHA is worth a try as well as example 11.
radical-dev
Posts: 45
Joined: Thu Apr 24, 2008 7:54 pm
Location: Wickede, Germany

Post by radical-dev »

Is the Texture white.png completely white? If so, the u should know, that white means NO transparency at all with EMT_TRANSPARENT_ADD_COLOR
danut007ro
Posts: 16
Joined: Thu Apr 12, 2007 2:21 pm

not working

Post by danut007ro »

Here is the updated code.
I build the image with paint.NET, it's a 128x128 filled image saved as a 32bit png, so it must have alpha channel
But I still don't understand why EMT_TRANSPARENT_ADD_COLOR doesn't work, but with the dwarf model in tutorial 09 (MeshViewer) it works. Sorry, but I'm very new with irrlicht, this should be simple

Code: Select all

#include <irrlicht.h>

using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

#ifdef _IRR_WINDOWS_
#pragma comment(lib, "Irrlicht.lib")
#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")
#endif

int main(int argc, char *argv[])
{
	IrrlichtDevice *device = createDevice(video::EDT_DIRECT3D9, dimension2d<s32>(320, 240), 24, false, true, false, 0);
	if (!device)
		return 1;
	device->setWindowCaption(L"Balls TEST");
	IVideoDriver* driver = device->getVideoDriver();
	ISceneManager* smgr = device->getSceneManager();
	IGUIEnvironment* guienv = device->getGUIEnvironment();
	driver->setTextureCreationFlag(video::ETCF_ALWAYS_32_BIT, true);

	smgr->addLightSceneNode(0, vector3df(0, 0, -60));

	IMeshSceneNode *bowl = smgr->addSphereSceneNode(10, 32);
	if (bowl)
	{
		bowl->setMaterialFlag(EMF_LIGHTING, true);
		bowl->setMaterialFlag(EMF_BACK_FACE_CULLING, true);
		bowl->setMaterialTexture(0, driver->getTexture("white.png"));
		bowl->setMaterialType(video::EMT_TRANSPARENT_VERTEX_ALPHA);
	}

	smgr->addCameraSceneNodeFPS(0, 100, 0.05);

	while (device->run())
	{
		driver->beginScene(true, true, SColor(255, 0, 0, 0));
		smgr->drawAll();
		guienv->drawAll();
		driver->endScene();
	}

	device->drop();
	return 0;
}
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

You can use VERTEX_ALPHA, but you have to set the vertex alpha in that case (with the mesh manipulator). ADD_COLOR makes the mesh more transparent the more black you have at some point. ALPHA_CHANNEL will work with textures that have an alpha channel, but of course you have to set the proper value for the alpha channel. Just saving the image as 32bit does not help, since the default alpha value should be 255, meaning opaque.
Post Reply