screenshot.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. // Tests screenshots features
  6. bool testShots(video::E_DRIVER_TYPE type)
  7. {
  8. IrrlichtDevice *device = createDevice(type, core::dimension2d<u32>(160, 120), 32);
  9. if (!device)
  10. return true;
  11. video::IVideoDriver* driver = device->getVideoDriver();
  12. scene::ISceneManager * smgr = device->getSceneManager();
  13. logTestString("Testing driver %ls\n", driver->getName());
  14. scene::IAnimatedMesh* mesh = smgr->getMesh("../media/sydney.md2");
  15. scene::IAnimatedMeshSceneNode* node;
  16. if (!mesh)
  17. return false;
  18. node = smgr->addAnimatedMeshSceneNode(mesh);
  19. if (!node)
  20. return false;
  21. stabilizeScreenBackground(driver);
  22. node->setPosition(core::vector3df(20, 0, 30));
  23. node->setMaterialFlag(video::EMF_LIGHTING, false);
  24. node->setMaterialTexture(0, driver->getTexture("../media/sydney.bmp"));
  25. node->setLoopMode(false);
  26. smgr->addCameraSceneNode();
  27. node->setMD2Animation(scene::EMAT_DEATH_FALLBACK);
  28. node->setCurrentFrame((f32)(node->getEndFrame()));
  29. node->setAnimationSpeed(0);
  30. device->run();
  31. driver->beginScene(true, true, video::SColor(255, 255, 255, 0));
  32. smgr->drawAll();
  33. driver->endScene();
  34. for (s32 i=0; i<video::ECF_UNKNOWN; ++i)
  35. {
  36. video::IImage* img = driver->createScreenShot((video::ECOLOR_FORMAT)i);
  37. logTestString("Color Format %d %ssupported\n", i, (img && img->getColorFormat() == i)?"":"un");
  38. #if 0 // Enable for a quick check while testing.
  39. // If someone adds comparison images please use another scene without animation
  40. // and maybe a texture using the full color spectrum.
  41. if ( img )
  42. {
  43. irr::core::stringc screenshotFilename = "results/";
  44. screenshotFilename += shortDriverName(driver);
  45. screenshotFilename += "screenshot";
  46. screenshotFilename += core::stringc(i);
  47. screenshotFilename += ".png";
  48. driver->writeImageToFile(img, screenshotFilename.c_str());
  49. }
  50. #endif
  51. if (img)
  52. img->drop();
  53. }
  54. device->closeDevice();
  55. device->run();
  56. device->drop();
  57. return true;
  58. }
  59. bool screenshot()
  60. {
  61. bool result = true;
  62. TestWithAllHWDrivers(testShots);
  63. return result;
  64. }