I included freeglut to use features of stencil buffer, while using irrlicht to draw. It works fine when rendering directly.
But when I add the render to target feature, strange thing happened.
It seems that stencil buffer test just doesn't work while rendering to target. (Because I can change the color of the area I was supposed to set stencil buffer) Any idea what is going on and how to fix it?
My code.
Code: Select all
#include <irrlicht.h>
#include <GL/freeglut.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()
{
IrrlichtDevice *device =
createDevice(video::EDT_OPENGL, dimension2d<u32>(800, 600), 16,
false, true, true, 0);
if (!device)
return 1;
device->setWindowCaption(L"Hello World! - Irrlicht Engine Demo");
IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
IGUIEnvironment* guienv = device->getGUIEnvironment();
IAnimatedMesh* mesh = smgr->getMesh("../media/f14/f14d.obj");
if (!mesh)
{
device->drop();
return 1;
}
IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode(mesh);
if (node)
{
node->setMaterialFlag(EMF_LIGHTING, true);
node->setMaterialFlag(video::EMF_NORMALIZE_NORMALS, true);
node->setScale(core::vector3df(3,3,3));
node->setRotation(core::vector3df(0,135,0));
}
smgr->addLightSceneNode(0, core::vector3df(2000, 2000, 2000), video::SColorf(1.0f, 1.0f, 1.0f), 20000);
smgr->addLightSceneNode(0, core::vector3df(2000, 2000, -2000), video::SColorf(1.0f, 1.0f, 1.0f), 20000);
smgr->setAmbientLight(video::SColorf(0.3f, 0.3f, 0.3f));
scene::ICameraSceneNode* currentCamera = smgr->addCameraSceneNodeFPS();
currentCamera->setFarValue(20000.f);
currentCamera->setPosition(core::vector3df(0, 0, -70));
currentCamera->setTarget(core::vector3df(0, 30, 0));
//===============================================
video::ITexture* rt = 0;
rt = driver->addRenderTargetTexture(core::dimension2d<u32>(800, 600), "RTT1");
// add fixed camera
while (device->run())
{
//driver->beginScene(true, true, SColor(255, 100, 101, 140));
driver->setRenderTarget(rt, true, true, SColor(255, 100, 101, 140));
glClearStencil(0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glEnable(GL_STENCIL_TEST);
glStencilFunc(GL_NEVER, 0x1, 0x1);
glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
driver->draw2DRectangle(
video::SColor(255, 255, 0, 0),
core::rect<s32>(0,0,400,600)
);
glStencilFunc(GL_EQUAL, 0x1, 0x1);
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
smgr->drawAll();
driver->setRenderTarget(0, true, true, 0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
glDisable(GL_STENCIL_TEST);
driver->draw2DImage(rt, core::position2d<s32>(10, 10),
core::rect<s32>(0, 0, 800, 600), 0,
video::SColor(255, 255, 255, 255), true);
guienv->drawAll();
driver->endScene();
}
device->drop();
return 0;
}
Solution: Use the trunk rather than the release version.
=========================================================================