material.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #include "testUtils.h"
  2. using namespace irr;
  3. static bool polygonOffset(video::E_DRIVER_TYPE type)
  4. {
  5. IrrlichtDevice* device = createDevice(type, core::dimension2d<u32>(160, 120));
  6. if (device == 0)
  7. return true;
  8. video::IVideoDriver* driver = device->getVideoDriver();
  9. if (!driver->queryFeature(video::EVDF_POLYGON_OFFSET))
  10. {
  11. device->closeDevice();
  12. device->run();
  13. device->drop();
  14. return true;
  15. }
  16. stabilizeScreenBackground(driver);
  17. scene::ISceneManager* smgr = device->getSceneManager();
  18. // create first plane
  19. scene::ISceneNode* plane = smgr->addMeshSceneNode(smgr->addHillPlaneMesh(
  20. "plane", core::dimension2df(10,10), core::dimension2du(2,2)), 0, -1,
  21. core::vector3df(0,0,20), core::vector3df(270,0,0));
  22. if (plane)
  23. {
  24. plane->setMaterialTexture(0, driver->getTexture("../media/t351sml.jpg"));
  25. plane->setMaterialFlag(video::EMF_LIGHTING, false);
  26. plane->setMaterialFlag(video::EMF_BACK_FACE_CULLING, true);
  27. }
  28. // create second plane exactly on top of the first one
  29. scene::ISceneNode* plane2 = smgr->addMeshSceneNode(smgr->addHillPlaneMesh(
  30. "plane2", core::dimension2df(5,5), core::dimension2du(2,2)), 0, -1,
  31. core::vector3df(0,0,20), core::vector3df(270,0,0));
  32. plane2->setMaterialFlag(video::EMF_BACK_FACE_CULLING, false);
  33. smgr->addCameraSceneNode();
  34. // test back plane to back
  35. plane->getMaterial(0).PolygonOffsetDirection=video::EPO_BACK;
  36. plane->getMaterial(0).PolygonOffsetFactor=7;
  37. driver->beginScene(true, true, video::SColor(255,113,113,133));
  38. smgr->drawAll();
  39. driver->endScene();
  40. bool result = takeScreenshotAndCompareAgainstReference(driver, "-polygonBack.png");
  41. //reset back plane
  42. plane->getMaterial(0).PolygonOffsetFactor=0;
  43. // test front plane to front
  44. plane2->getMaterial(0).PolygonOffsetDirection=video::EPO_FRONT;
  45. plane2->getMaterial(0).PolygonOffsetFactor=7;
  46. driver->beginScene(true, true, video::SColor(255,113,113,133));
  47. smgr->drawAll();
  48. driver->endScene();
  49. result &= takeScreenshotAndCompareAgainstReference(driver, "-polygonFront.png");
  50. device->closeDevice();
  51. device->run();
  52. device->drop();
  53. return result;
  54. }
  55. bool material()
  56. {
  57. bool result = true;
  58. TestWithAllDrivers(polygonOffset);
  59. return result;
  60. }