You mean Irrlicht is no longer maintained. I was thinking of going into openGL before putting too much time building anything serious with Irrlicht so I guess it would be good to know before hand.
It seems that the water effect does show as transparent across the spheres, albeit a bit blended but I guess looking through a tinted window would be the same in the real world. I used the water and stones jpgs from tutorial 8 special FX.
Code: Select all
#include <irrlicht.h>
#include <ITexture.h>
#include <iostream>
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();
scene::IMeshManipulator* mesh = smgr->getMeshManipulator();
scene::ICameraSceneNode* cam = smgr->addCameraSceneNodeFPS( 0, 50.0f, 0.01f, -1, 0, 0, false, 0.0f, false, true);
//lighting
smgr->addLightSceneNode( 0, core::vector3df(-50.0f,10.0f,-50.0f), video::SColorf(1.0f,1.0f,1.0f,0.0f), 5000.0f );
//water and textures
scene::IAnimatedMesh* plane_mesh = smgr->addHillPlaneMesh( "water_plane", core::dimension2d<f32>(20,20), core::dimension2d<u32>(40,40), 0, 0, core::dimension2d<f32>(0,0), core::dimension2d<f32>(10,10));
scene::ISceneNode* water_node = smgr->addWaterSurfaceSceneNode ( plane_mesh, 2.0f, 300.0f, 10.0f, 0, -1, core::vector3df(0, -5.0f, 0), core::vector3df(0, 0, 0), core::vector3df(1.0f, 1.0f, 1.0f));
water_node->setMaterialTexture(0, driver->getTexture("stones.jpg"));
water_node->setMaterialTexture(1, driver->getTexture("water.jpg"));
water_node->setMaterialType(video::EMT_REFLECTION_2_LAYER);
device->getCursorControl()->setVisible(false);
//sphere 1
scene::IMeshSceneNode* sphere_1 = smgr->addSphereSceneNode(radius, 16, 0, -1, core::vector3df(0, 0, 0), core::vector3df(0, 0, 0), core::vector3df(1.0f, 1.0f, 1.0f));
sphere_1->setMaterialFlag(video::EMF_LIGHTING, true);
sphere_1->setMaterialType(video::EMT_SOLID);
video::ITexture* tex = driver->getTexture("graph.jpg");
std::cout<<tex->hasAlpha()<<std::endl;
sphere_1->setMaterialTexture( 0, tex);
sphere_1->setMaterialType(video::EMT_TRANSPARENT_VERTEX_ALPHA);
smgr->getMeshManipulator()->setVertexColors(sphere_1->getMesh(), video::SColor( 155, 0, 255, 0));
mesh->setVertexColorAlpha(sphere_1->getMesh(), 0);
//sphere 2
scene::IMeshSceneNode* sphere_2 = smgr->addSphereSceneNode(radius+1, 16, 0, -1, core::vector3df(0, 0, 0), core::vector3df(0, 0, 0), core::vector3df(1.0f, 1.0f, 1.0f));
sphere_2->setMaterialFlag(video::EMF_LIGHTING, true);
sphere_2->setMaterialType(video::EMT_SOLID);
sphere_2->setMaterialType(video::EMT_TRANSPARENT_VERTEX_ALPHA);
smgr->getMeshManipulator()->setVertexColors(sphere_2->getMesh(), video::SColor( 155, 255, 0, 0));
mesh->setVertexColorAlpha(sphere_2->getMesh(), 155);
cam->setPosition( core::vector3df( 0, 0,-15));
cam->setTarget( core::vector3df( 0.0f, 0.0f, 0.0f));
int lastFPS = -1;
int alpha = 0;
while(device->run())
if (device->isWindowActive())
{
if(alpha < 256)
{
mesh->setVertexColorAlpha(sphere_1->getMesh(), alpha);
alpha++;
}
else
alpha = 0;
driver->beginScene(true, true, video::SColor( 0, 0, 0, 155));
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;
}