main.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. #include <iostream>
  2. #include <irrlicht/irrlicht.h>
  3. #include <sstream>
  4. #include <wallpaperengine/config.h>
  5. #include <wallpaperengine/video/renderer.h>
  6. #include <wallpaperengine/video/material.h>
  7. #include "wallpaperengine/shaders/compiler.h"
  8. #include "wallpaperengine/project.h"
  9. #include "wallpaperengine/irrlicht.h"
  10. int WinID = 0;
  11. irr::SIrrlichtCreationParameters _irr_params;
  12. irr::f32 g_AnimationSpeed = 0.1f;
  13. irr::f32 g_Scale = 2.5f;
  14. irr::f32 g_ScrollSpeed = 0.0f;
  15. irr::f32 g_Direction = 0.0f;
  16. irr::f32 g_Strength = 0.07f;
  17. irr::f32 g_SpecularPower = 1.0f;
  18. irr::f32 g_SpecularStrength = 1.0f;
  19. irr::f32 g_SpecularColor [3] = {1.0f, 1.0f, 1.0f};
  20. irr::f32 g_Texture1Resolution [4] = {1.0f, 1.0f, 1.0f, 1.0f};
  21. irr::f32 g_Texture0 = 0;
  22. irr::f32 g_Texture1 = 1;
  23. irr::f32 g_Texture2 = 2;
  24. irr::f32 g_Time = 0;
  25. class MyShaderCallback : public irr::video::IShaderConstantSetCallBack
  26. {
  27. virtual void OnSetConstants (irr::video::IMaterialRendererServices* services, int32_t userData)
  28. {
  29. irr::video::IVideoDriver* driver = services->getVideoDriver ();
  30. irr::core::matrix4 worldViewProj;
  31. worldViewProj = driver->getTransform(irr::video::ETS_PROJECTION);
  32. worldViewProj *= driver->getTransform(irr::video::ETS_VIEW);
  33. worldViewProj *= driver->getTransform(irr::video::ETS_WORLD);
  34. services->setVertexShaderConstant ("g_AnimationSpeed", &g_AnimationSpeed, 1);
  35. services->setVertexShaderConstant ("g_Scale", &g_Scale, 1);
  36. services->setVertexShaderConstant ("g_ScrollSpeed", &g_ScrollSpeed, 1);
  37. services->setVertexShaderConstant ("g_Direction", &g_Direction, 1);
  38. services->setVertexShaderConstant ("g_Time", &g_Time, 1);
  39. services->setVertexShaderConstant ("g_ModelViewProjectionMatrix", worldViewProj.pointer(), 16);
  40. services->setVertexShaderConstant ("g_Texture0Resolution", g_Texture1Resolution, 4);
  41. services->setVertexShaderConstant ("g_Texture1Resolution", g_Texture1Resolution, 4);
  42. services->setVertexShaderConstant ("g_Texture2Resolution", g_Texture1Resolution, 4);
  43. // TODO: Support up to 7 materials (as wallpaper engine)
  44. services->setPixelShaderConstant ("g_Strength", &g_Strength, 1);
  45. services->setPixelShaderConstant ("g_SpecularPower", &g_SpecularPower, 1);
  46. services->setPixelShaderConstant ("g_SpecularStrength", &g_SpecularStrength, 1);
  47. services->setPixelShaderConstant ("g_SpecularColor", g_SpecularColor, 3);
  48. services->setPixelShaderConstant ("g_Texture0", &g_Texture0, 1);
  49. services->setPixelShaderConstant ("g_Texture1", &g_Texture1, 1);
  50. services->setPixelShaderConstant ("g_Texture2", &g_Texture2, 1);
  51. }
  52. };
  53. int init_irrlicht()
  54. {
  55. // prepare basic configuration for irrlicht
  56. _irr_params.AntiAlias = 8;
  57. _irr_params.Bits = 16;
  58. // _irr_params.DeviceType = irr::EIDT_X11;
  59. _irr_params.DriverType = irr::video::EDT_OPENGL;
  60. _irr_params.Doublebuffer = true;
  61. _irr_params.EventReceiver = nullptr;
  62. _irr_params.Fullscreen = false;
  63. _irr_params.HandleSRGB = false;
  64. _irr_params.IgnoreInput = true;
  65. _irr_params.Stencilbuffer = true;
  66. _irr_params.UsePerformanceTimer = false;
  67. _irr_params.Vsync = false;
  68. _irr_params.WithAlphaChannel = false;
  69. _irr_params.ZBufferBits = 24;
  70. _irr_params.LoggingLevel = irr::ELL_DEBUG;
  71. _irr_params.WindowId = reinterpret_cast<void*> (WinID);
  72. wp::irrlicht::device = irr::createDeviceEx (_irr_params);
  73. if (wp::irrlicht::device == nullptr)
  74. {
  75. return 1;
  76. }
  77. wp::irrlicht::device->setWindowCaption (L"Test game");
  78. wp::irrlicht::driver = wp::irrlicht::device->getVideoDriver();
  79. return 0;
  80. }
  81. void preconfigure_wallpaper_engine ()
  82. {
  83. wp::config::path::base = wp::irrlicht::device->getFileSystem ()->getAbsolutePath ("../");
  84. wp::config::path::resources = wp::config::path::base + "/res";
  85. wp::config::path::shaders = wp::config::path::resources + "/shaders";
  86. wp::fs::resolver.changeWorkingDirectory(wp::config::path::base);
  87. }
  88. int main(int argc, char* argv[])
  89. {
  90. // parse the integer if it exists
  91. if (argc >= 1)
  92. {
  93. std::stringstream ss;
  94. ss << std::hex << argv[1];
  95. ss >> WinID;
  96. }
  97. printf("Initializing X11 to %d\n", WinID);
  98. if (init_irrlicht())
  99. {
  100. return 1;
  101. }
  102. preconfigure_wallpaper_engine ();
  103. // do_decompress ();
  104. irr::io::path _wp_engine_folder = "/home/almamu/Development/tmp/nier__automata_-_become_as_gods_edition/";
  105. // set our working directory
  106. wp::fs::resolver.changeWorkingDirectory (_wp_engine_folder);
  107. wp::project* wp_project = new wp::project ();
  108. if (wp_project->getScene ()->isOrthogonal() == true)
  109. {
  110. wp::video::renderer::setupOrthographicCamera (wp_project->getScene ());
  111. }
  112. else
  113. {
  114. wp::irrlicht::device->getLogger ()->log ("Non-orthogonal cameras not supported yet!!");
  115. return 0;
  116. }
  117. // register nodes
  118. wp::video::renderer::queueNode (wp_project->getScene ());
  119. int32_t lastTime = 0;
  120. int32_t minimumTime = 1000 / 90;
  121. int32_t currentTime = 0;
  122. while (wp::irrlicht::device->run () && wp::irrlicht::driver)
  123. {
  124. // if (device->isWindowActive ())
  125. {
  126. currentTime = wp::irrlicht::device->getTimer ()->getTime ();
  127. g_Time = currentTime / 1000.0f;
  128. if (currentTime - lastTime > minimumTime)
  129. {
  130. wp::video::renderer::render ();
  131. lastTime = currentTime;
  132. }
  133. else
  134. {
  135. wp::irrlicht::device->sleep (1, false);
  136. }
  137. }
  138. }
  139. return 0;
  140. }