how to use lights effects with driver.draw2DImage

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
AmigaIrr
Posts: 94
Joined: Mon Jan 10, 2005 7:55 am
Location: France, Alsace

how to use lights effects with driver.draw2DImage

Post by AmigaIrr »

Hello

I use driver.draw2DImage to draw a 2d tile map

i want tu use lights effects off this tiles...

How can i do this ?
L'eternité c'est long, surtout vers la fin...

Q6600 triton 79, 4 GO, 2* RAPTOR 150GO of ARECA 256 RAID 0, 3870 Zalmann, P5K. 24" Samsung. Antec nine hundred
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Hmm probably there's no way at all that you could do that...

Best thing would be to write a scene node which draws a tile for you (or all the tiles) and then you can use the lighting on the node.
Image Image Image
AmigaIrr
Posts: 94
Joined: Mon Jan 10, 2005 7:55 am
Location: France, Alsace

Post by AmigaIrr »

Thanks

But, how to do this ?
L'eternité c'est long, surtout vers la fin...

Q6600 triton 79, 4 GO, 2* RAPTOR 150GO of ARECA 256 RAID 0, 3870 Zalmann, P5K. 24" Samsung. Antec nine hundred
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

Image

Code: Select all

#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

int main()
{
   IrrlichtDevice * device =
      createDevice( video::EDT_OPENGL, dimension2d<s32>(640, 480), 32);

   IVideoDriver * driver = device->getVideoDriver();
   ISceneManager * smgr = device->getSceneManager();
   IGUIEnvironment * guienv = device->getGUIEnvironment();

   // Create an orthogonal (orthographic projection) camera
   ICameraSceneNode * camera = smgr->addCameraSceneNode(0, vector3df(0,0,-10), vector3df(0,0,0));
   matrix4 orthoMatrix;
   orthoMatrix.buildProjectionMatrixOrthoLH(20.f, 15.f, 5.f, 100.f);

    camera->setProjectionMatrix(orthoMatrix, true);      // SVN / 1.5
    //   camera->setProjectionMatrix(orthoMatrix);    // <= 1.4.2
    //   camera->setIsOrthogonal(true);


   // Create a simple quad mesh
   SMeshBuffer * buffer = new SMeshBuffer();
   S3DVertex vertices[4];
   vertices[0] = S3DVertex(0.5f, 0.5f, 0.0f, 0.0f, 0.0f, -1.0f, SColor(0, 255, 255, 255), 1.0f, 1.0f);
   vertices[1] = S3DVertex(0.5f, -0.5f, 0.0f, 0.0f, 0.0f, -0.5f, SColor(0, 255, 255, 255), 0.5f, 0.0f);
   vertices[2] = S3DVertex(-0.5f, -0.5f, 0.0f, 0.0f, 0.0f, -0.5f, SColor(0, 255, 255, 255), 0.0f, 0.0f);
   vertices[3] = S3DVertex(-0.5f, 0.5f, 0.0f, 0.0f, 0.0f, -0.5f, SColor(0, 255, 255, 255), 0.0f, 0.5f);
   u16 indices[6] = { 0, 1, 2, 0, 2, 3 };
   buffer->append(vertices, 4, indices, 6);

   SMesh * mesh = new SMesh();
   mesh->addMeshBuffer(buffer);
   buffer->drop();
   // That's our quad mesh created

   // Fill the screen with nodes that use this quad mesh. We are using an ortho camera
   // that defines a 20 x 15 view over 1x1 nodes, so we need 20 x 15 nodes.
   const u32 MAX_NODES = 20 * 15;

   IMeshSceneNode * nodes[MAX_NODES];
   
   for(int index = 0; index < MAX_NODES; ++index)
    {
        nodes[index] = smgr->addMeshSceneNode(mesh);

        if (nodes[index])
        {
            nodes[index]->setMaterialFlag(EMF_LIGHTING, true);
            ITexture * texture;

            u32 nodeX = index % 20;
            u32 nodeY = index / 20;
            nodes[index]->setPosition(vector3df((f32)nodeX - 9.5f, (f32)nodeY - 7.f, 0.f));

            if((nodeX + nodeY) % 2)
                texture = driver->getTexture("../../media/wall.bmp");
            else
                texture = driver->getTexture("../../media/detailmap3.jpg");

            nodes[index]->setMaterialTexture( 0, texture);
        }

    }

    mesh->drop();
    mesh = 0;

    // Move a light over the scene
    IBillboardSceneNode * billboard = smgr->addBillboardSceneNode();
    if(billboard)
    {
        billboard->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR );
        billboard->setMaterialTexture(0, driver->getTexture("../../media/particle.bmp"));
        billboard->setMaterialFlag(video::EMF_LIGHTING, false);
        billboard->setMaterialFlag(video::EMF_ZBUFFER, false);
        billboard->setSize(core::dimension2d<f32>(1.0f, 1.0f));

        ISceneNodeAnimator * animator = smgr->createFlyCircleAnimator(vector3df(0, 0, -1.f), 7.f, 0.001f, vector3df(0, 0, -1));
        if(animator)
        {
            billboard->addAnimator(animator);
            animator->drop();
            animator = 0;
        }

        (void)smgr->addLightSceneNode(billboard, vector3df(0, 0, 0), SColorf(1.f, 1.f, 0.f, 1.f), 5.f);
    }

    smgr->setAmbientLight(SColorf(0.25f, 0.25f, 0.5f, 1.0f));


    while(device->run())
    {
        driver->beginScene(true, true, SColor(255,100,101,140));
        smgr->drawAll();
        driver->endScene();
    }

    device->drop();

    return 0;
} 
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
AmigaIrr
Posts: 94
Joined: Mon Jan 10, 2005 7:55 am
Location: France, Alsace

Post by AmigaIrr »

thanks


but :

I use a big picture and picking small tiles.

is this possible with this system ?
L'eternité c'est long, surtout vers la fin...

Q6600 triton 79, 4 GO, 2* RAPTOR 150GO of ARECA 256 RAID 0, 3870 Zalmann, P5K. 24" Samsung. Antec nine hundred
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

AmigaIrr wrote:is this possible with this system ?
Be strong! The only obstacle is yourself.
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
AmigaIrr
Posts: 94
Joined: Mon Jan 10, 2005 7:55 am
Location: France, Alsace

Post by AmigaIrr »

BlindSide wrote:
AmigaIrr wrote:is this possible with this system ?
Be strong! The only obstacle is yourself.


?
L'eternité c'est long, surtout vers la fin...

Q6600 triton 79, 4 GO, 2* RAPTOR 150GO of ARECA 256 RAID 0, 3870 Zalmann, P5K. 24" Samsung. Antec nine hundred
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Means: Yes, just do it.
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

AmigaIrr wrote:I use a big picture and picking small tiles.

is this possible with this system ?
Anything is possible, with the exception of compassionate conservatism.

Can you be a bit more specific with your question? What is it about the (very basic) quad based tiling shown about that concerns you?
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
AmigaIrr
Posts: 94
Joined: Mon Jan 10, 2005 7:55 am
Location: France, Alsace

Post by AmigaIrr »

sorry, i'm french...


i want to use a sprite map (thath contains a lots of tiles (ex: 32*32) and i get with a loop all tiles i need.

exemple :

For y=0 To nbtilesy
For x=0 To nbtilesx
i=layer0[xdecarte,ydecarte] ' numero de la tile
driver.draw2DRectangle(_SCOLOR(100,55,55,255), _RECTI(debmapx+(x*tilesize)+8, debmapy+(y*tilesize)+8,debmapx+(x*tilesize)+20, debmapy+(y*tilesize)+20))

Next
Next


how tu use the mesh function to do this ?
L'eternité c'est long, surtout vers la fin...

Q6600 triton 79, 4 GO, 2* RAPTOR 150GO of ARECA 256 RAID 0, 3870 Zalmann, P5K. 24" Samsung. Antec nine hundred
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

AmigaIrr wrote:sorry, i'm french...
Well, better you than me.
AmigaIrr wrote:i want to use a sprite map (thath contains a lots of tiles (ex: 32*32) and i get with a loop all tiles i need.

Code: Select all

		For y=0 To nbtilesy
			For x=0 To nbtilesx
				i=layer0[xdecarte,ydecarte] ' numero de la tile
driver.draw2DRectangle(_SCOLOR(100,55,55,255), _RECTI(debmapx+(x*tilesize)+8, debmapy+(y*tilesize)+8,debmapx+(x*tilesize)+20, debmapy+(y*tilesize)+20))

			Next
		Next
I'm sorry, I don't really understand the connection between the text and the pseudocode. You don't appear to be using "i", and you are drawing coloured rectangles, not sprite images.

The sample code that I provided above is only intended to demonstrate a very simple way of drawing tiles using textured quads and an orthographic camera, to show that it's possible.

Each quad uses the entirety of a single texture. If you want to texture each quad with a portion of a larger sprite map, then you'll have to change the UV co-ordinates of the vertices making up each quad. You could do that in several ways, either by creating a different SMeshBuffer and SMesh for each scene node, or by using a custom scene node that draws itself, and can adjust the UVs of its vertices as necessary.

Example 03.CustomSceneNode shows you how to create a custom scene node that draws itself, and hopefully changing the UV coordinates of a S3DVertex should be obvious to someone who's been using Irrlicht for over three and a half years.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Post Reply