Page 2 of 3
Re: setting transparency (alpha) for spherescenenode?
Posted: Sun Mar 01, 2015 6:15 pm
by pandoragami
mongoose7 wrote:Code: Select all
Meshbuffer->Material.DiffuseColor.setAlpha( (s32)(value * 255) );
Meshbuffer->Material.MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA;
Sorry for my ignorance but how do I turn my sphere of IMeshSceneNode into a Meshbuffer?
Re: setting transparency (alpha) for spherescenenode?
Posted: Sun Mar 01, 2015 7:57 pm
by CuteAlien
IMesh (which you got from getMes()) has functions to access the meshbuffers. That node will only have one so you just need to access the first one.
Re: setting transparency (alpha) for spherescenenode?
Posted: Sun Mar 01, 2015 8:25 pm
by pandoragami
CuteAlien wrote:IMesh (which you got from getMes()) has functions to access the meshbuffers. That node will only have one so you just need to access the first one.
I think I have it right but still no transparency
Code: Select all
#include <irrlicht.h>
using namespace irr;
class MyEventReceiver : public IEventReceiver
{
public:
struct SMouseState
{
core::position2di Position;
bool LeftButtonDown;
SMouseState() : LeftButtonDown(false) { }
} MouseState;
virtual bool OnEvent(const SEvent& event)
{
if (event.EventType == irr::EET_KEY_INPUT_EVENT)
KeyIsDown[event.KeyInput.Key] = event.KeyInput.PressedDown;
if(event.EventType == EET_MOUSE_INPUT_EVENT)
{
switch(event.MouseInput.Event)
{
case EMIE_LMOUSE_PRESSED_DOWN:
MouseState.LeftButtonDown = true;
break;
case EMIE_LMOUSE_LEFT_UP:
MouseState.LeftButtonDown = false;
break;
case EMIE_MOUSE_MOVED:
MouseState.Position.X = event.MouseInput.X;
MouseState.Position.Y = event.MouseInput.Y;
break;
default:
break;
}
}
return false;
}
// This is used to check whether a key is being held down
virtual bool IsKeyDown(EKEY_CODE keyCode) const
{
return KeyIsDown[keyCode];
}
const SMouseState & GetMouseState(void) const
{
return MouseState;
}
MyEventReceiver()
{
for (u32 i=0; i<KEY_KEY_CODES_COUNT; ++i)
KeyIsDown[i] = false;
}
private:
// We use this array to store the current state of each key
bool KeyIsDown[KEY_KEY_CODES_COUNT];
};
MyEventReceiver receiver;
IrrlichtDevice* device = 0;
const int SCRX = 640;
const int SCRY = 480;
const float radius = 5.0f;
int main()
{
device = createDevice( irr::video::EDT_OPENGL, core::dimension2d<u32>( SCRX, SCRY), 16, false, false, false, &receiver);
if (device == 0)
return 1;
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, true);
scene::ICameraSceneNode* cam = smgr->addCameraSceneNodeFPS( 0, 50.0f, 0.01f, -1, 0, 0, false, 0.0f, false, true);
device->getCursorControl()->setVisible(false);
scene::IMeshSceneNode* sphere = smgr->addSphereSceneNode(radius, 32, 0, -1, core::vector3df(0, 0, 0), core::vector3df(0, 0, 0), core::vector3df(1.0f, 1.0f, 1.0f));
sphere->setMaterialFlag(video::EMF_LIGHTING, false);
sphere->setMaterialTexture( 0, driver->getTexture("graph.jpg"));
scene::IMesh* sphere_mesh = sphere->getMesh();
int value = 0;
scene::IMeshBuffer* sphere_mesh_buffer = sphere_mesh->getMeshBuffer(0);
sphere_mesh_buffer->getMaterial().DiffuseColor.setAlpha( (s32)(value * 255) );
sphere_mesh_buffer->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
cam->setPosition( core::vector3df( 0, 0,-15));
cam->setTarget( core::vector3df( 0.0f, 0.0f, 0.0f));
int lastFPS = -1;
while(device->run())
if (device->isWindowActive())
{
driver->beginScene(true, true, video::SColor( 255, 0, 0, 0));
smgr->drawAll();
driver->endScene();
int fps = driver->getFPS();
if (lastFPS != fps)
{
core::stringw str = L"Irrlicht Text Node [";
str += driver->getName();
str += "] FPS:";
str += fps;
device->setWindowCaption(str.c_str());
lastFPS = fps;
}
device->sleep(50);
}
device->drop();
return 0;
}
Re: setting transparency (alpha) for spherescenenode?
Posted: Sun Mar 01, 2015 9:35 pm
by CuteAlien
Oh come on - try a little bit before asking each step. Try using 0 again for example instead of 255.
Re: setting transparency (alpha) for spherescenenode?
Posted: Sun Mar 01, 2015 10:32 pm
by pandoragami
CuteAlien wrote:Oh come on - try a little bit before asking each step. Try using 0 again for example instead of 255.
I tried 0 or 255 but no luck. Am I missing some other mesh material methods?
Code: Select all
scene::IMesh* sphere_mesh = sphere->getMesh();
scene::IMeshBuffer* sphere_mesh_buffer = sphere_mesh->getMeshBuffer(0);
sphere_mesh_buffer->getMaterial().DiffuseColor.setAlpha( 0 );
sphere_mesh_buffer->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
Re: setting transparency (alpha) for spherescenenode?
Posted: Mon Mar 02, 2015 12:33 am
by mongoose7
You may need a texture.
Re: setting transparency (alpha) for spherescenenode?
Posted: Mon Mar 02, 2015 1:19 am
by pandoragami
mongoose7 wrote:You may need a texture.
thanks,
Besides this line?
Code: Select all
sphere->setMaterialTexture( 0, driver->getTexture("graph.jpg"));
The image does show on the sphere no problem. Is there something else I need to add for the texture? Is there transparency alpha for the texture itself?
Re: setting transparency (alpha) for spherescenenode?
Posted: Mon Mar 02, 2015 1:20 am
by pandoragami
Here's the complete code
Code: Select all
#include <irrlicht.h>
using namespace irr;
class MyEventReceiver : public IEventReceiver
{
public:
struct SMouseState
{
core::position2di Position;
bool LeftButtonDown;
SMouseState() : LeftButtonDown(false) { }
} MouseState;
virtual bool OnEvent(const SEvent& event)
{
if (event.EventType == irr::EET_KEY_INPUT_EVENT)
KeyIsDown[event.KeyInput.Key] = event.KeyInput.PressedDown;
if(event.EventType == EET_MOUSE_INPUT_EVENT)
{
switch(event.MouseInput.Event)
{
case EMIE_LMOUSE_PRESSED_DOWN:
MouseState.LeftButtonDown = true;
break;
case EMIE_LMOUSE_LEFT_UP:
MouseState.LeftButtonDown = false;
break;
case EMIE_MOUSE_MOVED:
MouseState.Position.X = event.MouseInput.X;
MouseState.Position.Y = event.MouseInput.Y;
break;
default:
break;
}
}
return false;
}
// This is used to check whether a key is being held down
virtual bool IsKeyDown(EKEY_CODE keyCode) const
{
return KeyIsDown[keyCode];
}
const SMouseState & GetMouseState(void) const
{
return MouseState;
}
MyEventReceiver()
{
for (u32 i=0; i<KEY_KEY_CODES_COUNT; ++i)
KeyIsDown[i] = false;
}
private:
// We use this array to store the current state of each key
bool KeyIsDown[KEY_KEY_CODES_COUNT];
};
MyEventReceiver receiver;
IrrlichtDevice* device = 0;
const int SCRX = 640;
const int SCRY = 480;
const float radius = 5.0f;
int main()
{
device = createDevice( irr::video::EDT_OPENGL, core::dimension2d<u32>( SCRX, SCRY), 16, false, false, false, &receiver);
if (device == 0)
return 1;
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, true);
scene::ICameraSceneNode* cam = smgr->addCameraSceneNodeFPS( 0, 50.0f, 0.01f, -1, 0, 0, false, 0.0f, false, true);
device->getCursorControl()->setVisible(false);
scene::IMeshSceneNode* sphere = smgr->addSphereSceneNode(radius, 32, 0, -1, core::vector3df(0, 0, 0), core::vector3df(0, 0, 0), core::vector3df(1.0f, 1.0f, 1.0f));
sphere->setMaterialFlag(video::EMF_LIGHTING, false);
sphere->setMaterialTexture( 0, driver->getTexture("graph.jpg"));
scene::IMesh* sphere_mesh = sphere->getMesh();
scene::IMeshBuffer* sphere_mesh_buffer = sphere_mesh->getMeshBuffer(0);
sphere_mesh_buffer->getMaterial().DiffuseColor.setAlpha( 0 );
sphere_mesh_buffer->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
cam->setPosition( core::vector3df( 0, 0,-15));
cam->setTarget( core::vector3df( 0.0f, 0.0f, 0.0f));
int lastFPS = -1;
while(device->run())
if (device->isWindowActive())
{
driver->beginScene(true, true, video::SColor( 255, 0, 0, 0));
smgr->drawAll();
driver->endScene();
int fps = driver->getFPS();
if (lastFPS != fps)
{
core::stringw str = L"Irrlicht Text Node [";
str += driver->getName();
str += "] FPS:";
str += fps;
device->setWindowCaption(str.c_str());
lastFPS = fps;
}
device->sleep(50);
}
device->drop();
return 0;
}
Re: setting transparency (alpha) for spherescenenode?
Posted: Mon Mar 02, 2015 1:33 am
by CuteAlien
Play around with the code. Did you try other material types with transparency? There is even an example (22) where you can try texture/light/material combinations. What's the point if other people are doing that for you ...
Please don't ask for every step - try figuring stuff out on your own. And only if you haven't found the solution after a day or so ask for help. It's the best way to become a better programmer - getting results just told will not help you at all in the long run.
Re: setting transparency (alpha) for spherescenenode?
Posted: Mon Mar 02, 2015 2:41 am
by pandoragami
CuteAlien wrote:Play around with the code. Did you try other material types with transparency? There is even an example (22) where you can try texture/light/material combinations. What's the point if other people are doing that for you ...
Please don't ask for every step - try figuring stuff out on your own. And only if you haven't found the solution after a day or so ask for help. It's the best way to become a better programmer - getting results just told will not help you at all in the long run.
Are you sure this isn't a bug though, everything makes sense in the code but it doesn't work. I don't want to waste time looking around for something if it won't work that's all, thanks for the help so far though.
Re: setting transparency (alpha) for spherescenenode?
Posted: Mon Mar 02, 2015 3:33 am
by CuteAlien
I don't know materials behavior myself without trying out stuff and looking at the results. Well, doing it often enough I get maybe faster to the results by now. But I got a transparent node in the materialviewer by playing around for less than 2 minutes just changing the alpha value and materials a few times. If you consider such basic experiments a waste of your time, that's up to you. I have never found another way of really learning a tool besides trying stuff with it myself. Good luck.
Re: setting transparency (alpha) for spherescenenode?
Posted: Mon Mar 02, 2015 11:32 am
by mongoose7
I did say TRANSPARENT_VERTEX_ALPHA! Why did you use TRANSPARENT_ALPHA_CHANNEL? Do you want it easy or hard? I tried to give you the easy way - one level of alpha across the texture. But you want it hard - one texture for the diffuse and one for the transparency. Well, now you will have to work.
Re: setting transparency (alpha) for spherescenenode?
Posted: Mon Mar 02, 2015 9:22 pm
by pandoragami
Well, no problem, I wasn't able to fix it but I did get the transparency to work for a mesh without a texture, I'll just have to settle for that. I tried this page too
http://irrlicht.sourceforge.net/forum/v ... php?t=2679
but no luck using the second post
arena->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR);
Re: [SOLVED] setting transparency (alpha) for spherescenenod
Posted: Mon Mar 02, 2015 9:45 pm
by CuteAlien
I'd like to mention that I never said to use DiffuseColor alpha. But I suppose a programmer who really tries to find a solution would have tried also what happens when using getMeshManipulator()->setVertexColorAlpha() with the other material-type like I proposed. Kinda like it's done in the example which I mention now for the 3rd time and where you can try material-settings without coding a line.
But just give up - fine by me. Textures are just ruining the pure 3D style anyway!
Re: [SOLVED] setting transparency (alpha) for spherescenenod
Posted: Mon Mar 02, 2015 10:04 pm
by pandoragami
CuteAlien wrote: But I suppose a programmer who really tries to find a solution would have tried also what happens when using getMeshManipulator()->setVertexColorAlpha() with the other material-type like I proposed.
Alright well, these were the ones I did try
Code: Select all
sphere->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL);
sphere->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR);
sphere->setMaterialType(video::EMT_TRANSPARENT_VERTEX_ALPHA);
sphere->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF);
sphere->setMaterialType(video::EMT_TRANSPARENT_REFLECTION_2_LAYER);
and only the first one works for a mesh; are there other transparent material types or would I get other results mixing video::EMT_TRANSPARENT_ALPHA_CHANNEL with other "video::EMT...." types?