viewPort.cpp 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. using namespace video;
  8. using namespace io;
  9. using namespace gui;
  10. //! Tests view ports and text rendering.
  11. /** The result should be as follows: We have three times the same image, a billboard with a cube and the text in front.
  12. They are replicated three times, one centered in the screen without viewport, one in the upper left (qurter screen) and
  13. one on the right (half screen). The latter is stretched due to the changed aspect ratio.
  14. The two viewport scenes get the texture drawn over the center as well, using draw2dimage. This should mark the proper
  15. image position with the top left corner of the texture.
  16. Finally, each scene has a checkbox drawn at the left side, vertically centered. This will show whether GUI elements adhere
  17. to viewports as well. */
  18. static bool viewPortText(E_DRIVER_TYPE driverType)
  19. {
  20. IrrlichtDevice *device = createDevice( driverType, dimension2d<u32>(160, 120), 32);
  21. if (!device)
  22. return true; // Treat a failure to create a driver as benign; this saves a lot of #ifdefs
  23. IVideoDriver* driver = device->getVideoDriver();
  24. ISceneManager * smgr = device->getSceneManager();
  25. IGUIEnvironment* env = smgr->getGUIEnvironment();
  26. stabilizeScreenBackground(driver);
  27. env->addCheckBox(true, core::recti(10,60,28,82));
  28. logTestString("Testing driver %ls\n", driver->getName());
  29. IBillboardSceneNode * bnode = smgr->addBillboardSceneNode(0,dimension2d<f32>(32,32),core::vector3df(0,0,10));
  30. bnode->setMaterialFlag(video::EMF_LIGHTING, false);
  31. bnode->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR);
  32. bnode->setMaterialTexture(0, driver->getTexture("../media/fire.bmp"));
  33. smgr->addTextSceneNode(device->getGUIEnvironment()->getBuiltInFont(), L"TEST", video::SColor(255,255,255,255), 0);
  34. smgr->addCubeSceneNode();
  35. smgr->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0));
  36. driver->beginScene(video::ECBF_COLOR | video::ECBF_DEPTH, SColor(255,100,101,140));
  37. smgr->drawAll();
  38. env->drawAll();
  39. driver->setViewPort(rect<s32>(0,0,160/2,120/2));
  40. smgr->drawAll();
  41. env->drawAll();
  42. driver->draw2DImage(driver->getTexture("../media/fire.bmp"), core::vector2di(160/2,120/2));
  43. driver->setViewPort(rect<s32>(160/2,0,160,120));
  44. smgr->drawAll();
  45. env->drawAll();
  46. driver->draw2DImage(driver->getTexture("../media/fire.bmp"), core::vector2di(160/2,120/2));
  47. driver->endScene();
  48. bool result = takeScreenshotAndCompareAgainstReference(driver, "-viewPortText.png", 98.71f);
  49. device->closeDevice();
  50. device->run();
  51. device->drop();
  52. return result;
  53. }
  54. bool viewPort(void)
  55. {
  56. bool result = true;
  57. // TODO: software driver and burnings don't use view port for
  58. // 2d rendering, so result is pretty wrong.
  59. TestWithAllDrivers(viewPortText);
  60. return result;
  61. }