It's adapted from my old guice project and some rambling on #irrlicht which you should join if yer not here already.
It's a draw2DGrid function for anyone needing that sort of thing for say a gui editor or something like that. it may be a little more complex then nessesary even but should work easily for anyone.
this is just a modified version of the hello world demo it shouldn't be too difficult to understand what I did here even if you're a bit noobish.
#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")
#endif
IVideoDriver* driver;
//resolution values are normally read from config files
//which is why it's this way for now
s32 ResX = 1024; //width
s32 ResY = 768; //height
s32 GresX;
s32 GresY;
void draw2DGrid(s32 ResX, s32 ResY, s32 GridSize, bool isFullscreen, video::SColor XColor, video::SColor YColor)
{
if(isFullscreen)
{
ResX = driver->getScreenSize().Width;
ResY = driver->getScreenSize().Height;
}
GresX = ResX / GridSize;
GresY = ResY / GridSize;
// you can use 2d line but it's not as precise
for ( s32 x = 0; x < GresX; x++ )
{
driver->draw2DRectangle(XColor,rect<s32>(x*GridSize-1,0,x*GridSize,ResY));
// driver->draw2DLine(position2d<s32>(x*GridSize-1,0), position2d<s32>(x*GridSize,ResY),SColor(255,90,90,90));
}
for ( s32 y = 0; y < GresY; y++ )
{
driver->draw2DRectangle(YColor,rect<s32>(0,y*GridSize-1,ResX,y*GridSize));
// driver->draw2DLine(position2d<s32>(0,y*GridSize-1), position2d<s32>(ResX,y*GridSize),SColor(255,90,90,90));
}
}
int main()
{
IrrlichtDevice *device =
createDevice( video::EDT_DIRECT3D9, dimension2d<s32>(ResX, ResY), 16,
false, false, false, 0);
device->setWindowCaption(L"Midnight's 2D Grid - Irrlicht Engine Demo");
driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
IGUIEnvironment* guienv = device->getGUIEnvironment();
driver->setFog(video::SColor(200,200,60,60), false, 10.0, 20.0, 0.01, false, true);
guienv->addStaticText(L"Midnight's 2D Grid! This is the Irrlicht Software renderer!",
rect<s32>(10,10,260,22), true);
IAnimatedMesh* mesh = smgr->getMesh("sydney.md2");
IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh );
if (node)
{
node->setMaterialFlag(EMF_LIGHTING, false);
node->setMaterialFlag(EMF_FOG_ENABLE, true);
node->setMD2Animation ( scene::EMAT_STAND );
node->setMaterialTexture( 0, driver->getTexture("sydney.bmp") );
}
smgr->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0));
while(device->run())
{
driver->beginScene(true, true, SColor(255,100,101,140));
smgr->drawAll();
//we have to draw the grid before GUI if we want it to be behind the GUI
//if the grid fullscreen flag is set true then it ignores resolution values for easier of use
draw2DGrid(ResX,ResY,16,true,video::SColor(255,255,0,0),video::SColor(255,0,0,255));
guienv->drawAll();
driver->endScene();
}
device->drop();
return 0;
}
enjoy
