Minimap with Render to Texture

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
zprg
Competition winner
Posts: 30
Joined: Tue Jul 31, 2012 12:29 pm
Location: Germany

Minimap with Render to Texture

Post by zprg »

Minimap with Render to texture - i needed a minimap. I decided to draw the minimap to an irrlichttexture with Render to texture. this minimap-texture you can draw everywhere you want and dont have to rewrite the minimap everytime, only if something changes. The code you remember from the irrlicht tutorial "Render to texture": http://irrlicht.sourceforge.net/docu/example013.html

Code: Select all

 
 ...
int yourmap[40][30];
int height=30;
int width=40;
 
...
video::ITexture* rtmap = 0;
if (driver->queryFeature(video::EVDF_RENDER_TO_TARGET))
        {
                rtmap = driver->addRenderTargetTexture(core::dimension2d<u32>(1024,680), "rt");
// add fixed camera
                fixedCam = smgr->addCameraSceneNode(0, core::vector3df(10,10,-80),
                        core::vector3df(-10,10,-100));
}
else
{
    printf("Your hardware or this renderer is not able to use the\n render to texture feature. RTT Disabled. \n");
}
 
...
if (rtmap) 
{
    driver->setRenderTarget(rtmap);
    smgr->setActiveCamera(fixedCam);
    for (int z = 0; z<height; z++) //here we draw the map to the texture
     { 
         for (int x = 0; x < width; x++) 
         {
            if (yourmap[x][z]==0) //as example water, in my map water is 0
             {
                driver->draw2DRectangle(video::SColor(255,0,0,255), //blue for water
                    core::rect<s32>(x*2, z*2, x*2+1, z*2+1); //for example for every map-tile a 2x2 block on the map
                //and so on with the other terraintypes or build a colortable for the terraintypes
             }
           }
           //and also you can draw for example a white rect on the map with draw2DRectangle...
    }
    driver->setRenderTarget(0);
    smgr->setActiveCamera(hereinsertyournormalcamera);
}
driver->beginScene(true, true, SColor(0xFF000000));
 
//here your code
 
smgr->drawAll();
 
//minimap
driver->draw2DImage(rtmap, core::position2d<s32>(804,10), //position to draw the minimap on screen
    core::rect<s32>(0,0,212,150), 0,
    video::SColor(255,255,255,255), false);
 
driver->endScene();
...
 
Last edited by zprg on Fri Aug 24, 2012 4:28 pm, edited 1 time in total.
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: Minimap with Render to Texture

Post by serengeor »

A screenshot would be nice :)
Working on game: Marrbles (Currently stopped).
zprg
Competition winner
Posts: 30
Joined: Tue Jul 31, 2012 12:29 pm
Location: Germany

Re: Minimap with Render to Texture

Post by zprg »

a minimap is a minimap you see in the most strategy or mmo and so on. you can put it in the left or right, up or down,
transparent or not ?
http://en.wikipedia.org/wiki/Mini-map
Last edited by zprg on Wed Aug 22, 2012 5:48 pm, edited 2 times in total.
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Minimap with Render to Texture

Post by hendu »

Can't access that, tripod's hotlink protection is a bit too eager.
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: Minimap with Render to Texture

Post by serengeor »

I know what a minimap is, what I wanted was a screenshot of it in action :)
Working on game: Marrbles (Currently stopped).
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Minimap with Render to Texture

Post by hendu »

It'd create a pixelated map, from the code ;)

BTW if you create your maps in netradiant, it can create minimaps of them for you:
Image
Post Reply