Page 1 of 1

transparent sphere

Posted: Tue Mar 24, 2009 1:45 pm
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?

Posted: Tue Mar 24, 2009 9:08 pm
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.

Posted: Wed Mar 25, 2009 7:01 am
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

not working

Posted: Wed Mar 25, 2009 8:39 am
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;
}

Posted: Wed Mar 25, 2009 12:00 pm
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.