makeColorKeyTexture.cpp 2.2 KB

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