~baltix/+junk/irrlicht-test

« back to all changes in this revision

Viewing changes to tests/makeColorKeyTexture.cpp

  • Committer: Mantas Kriaučiūnas
  • Date: 2011-07-18 13:06:25 UTC
  • Revision ID: mantas@akl.lt-20110718130625-c5pvifp61e7kj1ol
Included whole irrlicht SVN libraries to work around launchpad recipe issue with quilt, see https://answers.launchpad.net/launchpad/+question/165193

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (C) 2008-2011 Colin MacDonald
 
2
// No rights reserved: this software is in the public domain.
 
3
 
 
4
#include "testUtils.h"
 
5
 
 
6
using namespace irr;
 
7
using namespace core;
 
8
using namespace scene;
 
9
using namespace video;
 
10
 
 
11
/** Test the behaviour of makeColorKeyTexture() using both 16 bit (software)
 
12
        and 32 bit (Burning) textures, with the new behaviour and the legacy
 
13
        behaviour. */
 
14
static bool doTestWith(E_DRIVER_TYPE driverType,
 
15
                                                bool zeroTexels)
 
16
{
 
17
        IrrlichtDevice *device = createDevice( driverType,
 
18
                                                                                        dimension2d<u32>(160, 120), 32);
 
19
        if (!device)
 
20
                return false;
 
21
 
 
22
        IVideoDriver* driver = device->getVideoDriver();
 
23
        ISceneManager * smgr = device->getSceneManager();
 
24
 
 
25
        // Draw a cube background so that we can check that the keying is working.
 
26
        ISceneNode * cube = smgr->addCubeSceneNode(50.f, 0, -1, vector3df(0, 0, 60));
 
27
        cube->setMaterialTexture(0, driver->getTexture("../media/wall.bmp"));
 
28
        cube->setMaterialFlag(video::EMF_LIGHTING, false);
 
29
 
 
30
        ITexture * Texture = device->getVideoDriver()->getTexture("../media/portal2.bmp");
 
31
 
 
32
        device->getVideoDriver()->makeColorKeyTexture(Texture,
 
33
                                                                                                  position2d<s32>(64,64),
 
34
                                                                                                  zeroTexels);
 
35
        device->getVideoDriver()->makeColorKeyTexture(Texture,
 
36
                                                                                                  position2d<s32>(64,64),
 
37
                                                                                                  zeroTexels);
 
38
        (void)smgr->addCameraSceneNode();
 
39
 
 
40
        driver->beginScene(true, true, SColor(255,100,101,140));
 
41
        smgr->drawAll();
 
42
 
 
43
        driver->draw2DImage(Texture,
 
44
                                                position2di(40, 40),
 
45
                                                rect<s32>(0, 0, Texture->getSize().Width, Texture->getSize().Height),
 
46
                                                0,
 
47
                                                SColor(255,255,255,255),
 
48
                                                true);
 
49
        driver->endScene();
 
50
 
 
51
        char screenshotName[256];
 
52
        (void)snprintf(screenshotName, 256, "-makeColorKeyTexture-%s.png",
 
53
                zeroTexels? "old" : "new");
 
54
 
 
55
        bool result = takeScreenshotAndCompareAgainstReference(driver, screenshotName);
 
56
 
 
57
        device->closeDevice();
 
58
        device->run();
 
59
        device->drop();
 
60
 
 
61
        return result;
 
62
}
 
63
 
 
64
bool makeColorKeyTexture(void)
 
65
{
 
66
        bool result = true;
 
67
        
 
68
        result &= doTestWith(EDT_BURNINGSVIDEO, false);
 
69
        result &= doTestWith(EDT_SOFTWARE, false);
 
70
        result &= doTestWith(EDT_BURNINGSVIDEO, true);
 
71
        result &= doTestWith(EDT_SOFTWARE, true);
 
72
 
 
73
        return result;
 
74
}