createImage.cpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. bool result = true;
  12. video::IVideoDriver* driver = device->getVideoDriver();
  13. video::ITexture* tex=driver->getTexture("../media/water.jpg");
  14. video::ITexture* tex1=0;
  15. video::ITexture* tex2=0;
  16. if (!tex)
  17. result=false;
  18. else
  19. {
  20. video::IImage* img1=driver->createImage(tex, core::vector2di(0,0), core::dimension2du(32,32));
  21. if (!img1)
  22. result=false;
  23. else
  24. {
  25. tex1=driver->addTexture("new1", img1);
  26. img1->drop();
  27. img1=0;
  28. }
  29. video::IImage* img2=driver->createImage(tex, core::vector2di(0,0), tex->getSize());
  30. if (!img2)
  31. result=false;
  32. else
  33. {
  34. tex2=driver->addTexture("new2", img2);
  35. img2->drop();
  36. img2 = 0;
  37. }
  38. }
  39. driver->beginScene(video::ECBF_COLOR | video::ECBF_DEPTH, video::SColor(255,255,0,255));//Backbuffer background is pink
  40. driver->draw2DImage(tex, core::position2d<s32>(0,0), core::recti(0,0,32,32));
  41. driver->draw2DImage(tex1, core::position2d<s32>(32,0));
  42. driver->draw2DImage(tex2, core::position2d<s32>(64,0), core::recti(0,0,32,32));
  43. driver->endScene();
  44. result = takeScreenshotAndCompareAgainstReference(driver, "-createImage.png");
  45. device->closeDevice();
  46. device->run();
  47. device->drop();
  48. return result;
  49. }
  50. bool testImageFormats()
  51. {
  52. IrrlichtDevice *device = createDevice(video::EDT_BURNINGSVIDEO, core::dimension2d<u32>(256,128));
  53. if (device == 0)
  54. return true; // could not create selected driver.
  55. video::IVideoDriver* driver = device->getVideoDriver();
  56. video::ITexture* tex=driver->getTexture("../media/water.jpg");
  57. video::ITexture* tex1=driver->getTexture("media/grey.tga");
  58. driver->beginScene(video::ECBF_COLOR | video::ECBF_DEPTH, video::SColor(255,0,0,0));
  59. driver->draw2DImage(tex, core::position2d<s32>(0,0), core::recti(0,0,64,64));
  60. driver->draw2DImage(tex1, core::position2d<s32>(0,64), core::recti(0,0,64,64));
  61. driver->endScene();
  62. bool result = takeScreenshotAndCompareAgainstReference(driver, "-testImageFormats.png", 99.5f);
  63. device->closeDevice();
  64. device->run();
  65. device->drop();
  66. return result;
  67. }
  68. }
  69. bool createImage()
  70. {
  71. bool result = testImageCreation();
  72. result &= testImageFormats();
  73. return result;
  74. }