material.cpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #include <WallpaperEngine/video/material.h>
  2. #include <WallpaperEngine/Irrlicht/CContext.h>
  3. extern WallpaperEngine::Irrlicht::CContext* IrrlichtContext;
  4. namespace WallpaperEngine
  5. {
  6. namespace video
  7. {
  8. material::material (irr::core::vector3df origin, WallpaperEngine::scene *scene)
  9. {
  10. m_origin = origin;
  11. m_scene = scene;
  12. m_material.Wireframe = false;
  13. m_material.Lighting = false;
  14. irr::f32 xright = this->m_origin.X;
  15. irr::f32 xleft = -this->m_origin.X;
  16. irr::f32 ztop = this->m_origin.Y;
  17. irr::f32 zbottom = -this->m_origin.Y;
  18. irr::f32 z = this->m_scene->getCamera ()->getEye ().Z;
  19. m_vertices [0].Pos = irr::core::vector3df (xleft, ztop, z); // top left
  20. m_vertices [1].Pos = irr::core::vector3df (xright, ztop, z); // top right
  21. m_vertices [2].Pos = irr::core::vector3df (xright, zbottom, z); // bottom right
  22. m_vertices [3].Pos = irr::core::vector3df (xleft, zbottom, z); // bottom left
  23. m_vertices [0].TCoords = irr::core::vector2df (1.0f, 0.0f);
  24. m_vertices [1].TCoords = irr::core::vector2df (0.0f, 0.0f);
  25. m_vertices [2].TCoords = irr::core::vector2df (0.0f, 1.0f);
  26. m_vertices [3].TCoords = irr::core::vector2df (1.0f, 1.0f);
  27. m_vertices [0].Color = irr::video::SColor (255, 255, 255, 255);
  28. m_vertices [1].Color = irr::video::SColor (255, 255, 255, 255);
  29. m_vertices [2].Color = irr::video::SColor (255, 255, 255, 255);
  30. m_vertices [3].Color = irr::video::SColor (255, 255, 255, 255);
  31. }
  32. void material::setFlag(irr::video::E_MATERIAL_FLAG flag, bool newvalue)
  33. {
  34. this->getMaterial ().setFlag (flag, newvalue);
  35. }
  36. void material::setType(irr::video::E_MATERIAL_TYPE newType)
  37. {
  38. this->getMaterial ().MaterialType = newType;
  39. }
  40. irr::video::SMaterial& material::getMaterial ()
  41. {
  42. return this->m_material;
  43. }
  44. void material::render ()
  45. {
  46. uint16_t indices[] =
  47. {
  48. 0, 1, 2, 3
  49. };
  50. IrrlichtContext->getDevice ()->getVideoDriver ()->setMaterial (m_material);
  51. IrrlichtContext->getDevice ()->getVideoDriver ()->drawVertexPrimitiveList (
  52. m_vertices, 4, indices, 1, irr::video::EVT_STANDARD, irr::scene::EPT_QUADS, irr::video::EIT_16BIT
  53. );
  54. }
  55. }
  56. }