main.cpp 6.2 KB

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