createImage.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #include "testUtils.h"
  2. using namespace irr;
  3. namespace
  4. {
  5. bool testImageCreation()
  6. {
  7. // create device
  8. IrrlichtDevice *device = createDevice(video::EDT_SOFTWARE, core::dimension2d<u32>(160,120));
  9. if (device == 0)
  10. return true; // could not create selected driver.
  11. video::IVideoDriver* driver = device->getVideoDriver();
  12. video::ITexture* tex=driver->getTexture("../media/water.jpg");
  13. video::IImage* img1=driver->createImage(tex, core::vector2di(0,0), core::dimension2du(32,32));
  14. video::ITexture* tex1=driver->addTexture("new1", img1);
  15. img1->drop();
  16. img1=0;
  17. video::IImage* img2=driver->createImage(tex, core::vector2di(0,0), tex->getSize());
  18. video::ITexture* tex2=driver->addTexture("new2", img2);
  19. img2->drop();
  20. img2 = 0;
  21. driver->beginScene(true, true, video::SColor(255,255,0,255));//Backbuffer background is pink
  22. driver->draw2DImage(tex, core::position2d<s32>(0,0), core::recti(0,0,32,32));
  23. driver->draw2DImage(tex1, core::position2d<s32>(32,0));
  24. driver->draw2DImage(tex2, core::position2d<s32>(64,0), core::recti(0,0,32,32));
  25. driver->endScene();
  26. bool result = takeScreenshotAndCompareAgainstReference(driver, "-createImage.png");
  27. device->closeDevice();
  28. device->run();
  29. device->drop();
  30. return result;
  31. }
  32. bool testImageFormats()
  33. {
  34. IrrlichtDevice *device = createDevice(video::EDT_BURNINGSVIDEO, core::dimension2d<u32>(256,128));
  35. if (device == 0)
  36. return true; // could not create selected driver.
  37. video::IVideoDriver* driver = device->getVideoDriver();
  38. video::ITexture* tex=driver->getTexture("../media/water.jpg");
  39. video::ITexture* tex1=driver->getTexture("media/grey.tga");
  40. driver->beginScene(true, true);
  41. driver->draw2DImage(tex, core::position2d<s32>(0,0), core::recti(0,0,64,64));
  42. driver->draw2DImage(tex1, core::position2d<s32>(0,64), core::recti(0,0,64,64));
  43. driver->endScene();
  44. bool result = takeScreenshotAndCompareAgainstReference(driver, "-testImageFormats.png", 99.5f);
  45. device->closeDevice();
  46. device->run();
  47. device->drop();
  48. return result;
  49. }
  50. }
  51. bool createImage()
  52. {
  53. bool result = testImageCreation();
  54. result &= testImageFormats();
  55. return result;
  56. }