lights.cpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Copyright (C) 2008-2012 Christian Stehno, Colin MacDonald
  2. // No rights reserved: this software is in the public domain.
  3. #include "testUtils.h"
  4. using namespace irr;
  5. static bool testLightTypes(video::E_DRIVER_TYPE driverType)
  6. {
  7. IrrlichtDevice *device = createDevice (driverType, core::dimension2d<u32>(256,128));
  8. if (!device)
  9. return true; // No error if device does not exist
  10. video::IVideoDriver* driver = device->getVideoDriver();
  11. scene::ISceneManager* smgr = device->getSceneManager();
  12. if (!driver->getDriverAttributes().getAttributeAsInt("MaxLights"))
  13. {
  14. device->closeDevice();
  15. device->run();
  16. device->drop();
  17. return true;
  18. }
  19. stabilizeScreenBackground(driver);
  20. logTestString("Testing driver %ls\n", driver->getName());
  21. // smgr->setAmbientLight(video::SColorf(0.3f,0.3f,0.3f));
  22. scene::ICameraSceneNode* cam = smgr->addCameraSceneNode();
  23. cam->setPosition(core::vector3df(0,200,0));
  24. cam->setTarget(core::vector3df());
  25. smgr->addAnimatedMeshSceneNode(device->getSceneManager()->addHillPlaneMesh("plane", core::dimension2df(4,4), core::dimension2du(128,128)));
  26. scene::ILightSceneNode* light1 = smgr->addLightSceneNode(0, core::vector3df(-100,30,-100));
  27. light1->setLightType(video::ELT_POINT);
  28. light1->setRadius(100.f);
  29. light1->getLightData().DiffuseColor.set(0,1,1);
  30. // smgr->addCubeSceneNode(10, light1)->setMaterialFlag(video::EMF_LIGHTING, false);
  31. scene::ILightSceneNode* light2 = smgr->addLightSceneNode(0, core::vector3df(100,30,100));
  32. light2->setRotation(core::vector3df(90,0,0));
  33. light2->setLightType(video::ELT_SPOT);
  34. light2->setRadius(100.f);
  35. light2->getLightData().DiffuseColor.set(1,0,0);
  36. light2->getLightData().InnerCone=10.f;
  37. light2->getLightData().OuterCone=30.f;
  38. // smgr->addCubeSceneNode(10, light2)->setMaterialFlag(video::EMF_LIGHTING, false);
  39. scene::ILightSceneNode* light3 = smgr->addLightSceneNode();
  40. light3->setRotation(core::vector3df(15,0,0));
  41. light3->setLightType(video::ELT_DIRECTIONAL);
  42. light1->getLightData().DiffuseColor.set(0,1,0);
  43. driver->beginScene(video::ECBF_COLOR | video::ECBF_DEPTH, video::SColor(0));
  44. smgr->drawAll();
  45. driver->endScene();
  46. const bool result = takeScreenshotAndCompareAgainstReference(driver, "-lightType.png", 99.91f);
  47. device->closeDevice();
  48. device->run();
  49. device->drop();
  50. return result;
  51. }
  52. bool lights(void)
  53. {
  54. bool result = true;
  55. // no lights in sw renderer
  56. TestWithAllDrivers(testLightTypes);
  57. return result;
  58. }