softwareDevice.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. //! Tests the basic functionality of the software device.
  8. bool softwareDevice(void)
  9. {
  10. IrrlichtDevice *device = createDevice(video::EDT_SOFTWARE, dimension2d<u32>(160, 120), 32);
  11. if (!device)
  12. return false;
  13. video::IVideoDriver* driver = device->getVideoDriver();
  14. ISceneManager * smgr = device->getSceneManager();
  15. // Test a particular rotation that highlighted a clipping issue from matrix::transformPlane()
  16. video::S3DVertex vertices[3];
  17. vertices[0] = video::S3DVertex(10,0,-10, 1,0,0,
  18. video::SColor(255,255,0,255), 1, 1);
  19. vertices[1] = video::S3DVertex(0,20,0, 0,1,1,
  20. video::SColor(255,255,255,0), 1, 0);
  21. vertices[2] = video::S3DVertex(-10,0,-10, 0,0,1,
  22. video::SColor(255,0,255,0), 0, 0);
  23. video::SMaterial material;
  24. material.Lighting = false;
  25. material.Wireframe = false;
  26. const u16 indices[] = { 1,0,2, };
  27. matrix4 transform(matrix4::EM4CONST_IDENTITY);
  28. vector3df rotations(290, 0, 290); // <-- This rotation used to clip the triangle incorrectly
  29. transform.setRotationDegrees(rotations);
  30. (void)smgr->addCameraSceneNode(0, core::vector3df(0,0,-40), core::vector3df(0,0,0));
  31. driver->beginScene(video::ECBF_COLOR | video::ECBF_DEPTH, video::SColor(255,255,255,0));
  32. smgr->drawAll();
  33. driver->setMaterial(material);
  34. driver->setTransform(video::ETS_WORLD, transform);
  35. driver->drawIndexedTriangleList(&vertices[0], 3, &indices[0], 1);
  36. driver->endScene();
  37. bool result = takeScreenshotAndCompareAgainstReference(driver, "-softwareDevice-rotatedClip.png");
  38. device->closeDevice();
  39. device->run();
  40. device->drop();
  41. return result;
  42. }