diff --git a/.gitignore b/.gitignore index 986415c..1028f3e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ cmake-build-debug -assets \ No newline at end of file +assets.zip +.idea \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 217ca7b..8423797 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,6 +15,6 @@ find_package(LZ4 REQUIRED) include_directories(${X11_INCLUDE_DIR} ${IRRLICHT_INCLUDE_DIR} ${LZ4_INCLUDE_DIR} .) -add_executable(wallengine main.cpp wallpaperengine/shaders/compiler.h wallpaperengine/shaders/compiler.cpp wallpaperengine/project.cpp wallpaperengine/project.h wallpaperengine/scene.cpp wallpaperengine/scene.h wallpaperengine/object.cpp wallpaperengine/object.h wallpaperengine/camera.cpp wallpaperengine/camera.h wallpaperengine/core.cpp wallpaperengine/core.h wallpaperengine/image.cpp wallpaperengine/image.h wallpaperengine/object3d.cpp wallpaperengine/object3d.h wallpaperengine/effect.cpp wallpaperengine/effect.h wallpaperengine/fs/utils.cpp wallpaperengine/fs/utils.h wallpaperengine/irrlicht.cpp wallpaperengine/irrlicht.h wallpaperengine/config.cpp wallpaperengine/config.h wallpaperengine/video/renderer.cpp wallpaperengine/video/renderer.h wallpaperengine/video/node.cpp wallpaperengine/video/node.h wallpaperengine/video/material.cpp wallpaperengine/video/material.h wallpaperengine/texture.cpp wallpaperengine/texture.h wallpaperengine/irr/CImageLoaderTEX.h wallpaperengine/irr/CImageLoaderTEX.cpp wallpaperengine/irr/CPkgReader.h wallpaperengine/irr/CPkgReader.cpp wallpaperengine/irr/CFileList.h wallpaperengine/irr/CFileList.cpp) +add_executable(wallengine main.cpp wallpaperengine/shaders/compiler.h wallpaperengine/shaders/compiler.cpp wallpaperengine/project.cpp wallpaperengine/project.h wallpaperengine/scene.cpp wallpaperengine/scene.h wallpaperengine/object.cpp wallpaperengine/object.h wallpaperengine/camera.cpp wallpaperengine/camera.h wallpaperengine/core.cpp wallpaperengine/core.h wallpaperengine/image.cpp wallpaperengine/image.h wallpaperengine/object3d.cpp wallpaperengine/object3d.h wallpaperengine/effect.cpp wallpaperengine/effect.h wallpaperengine/fs/utils.cpp wallpaperengine/fs/utils.h wallpaperengine/irrlicht.cpp wallpaperengine/irrlicht.h wallpaperengine/video/renderer.cpp wallpaperengine/video/renderer.h wallpaperengine/video/node.cpp wallpaperengine/video/node.h wallpaperengine/video/material.cpp wallpaperengine/video/material.h wallpaperengine/texture.cpp wallpaperengine/texture.h wallpaperengine/irr/CImageLoaderTEX.h wallpaperengine/irr/CImageLoaderTEX.cpp wallpaperengine/irr/CPkgReader.h wallpaperengine/irr/CPkgReader.cpp wallpaperengine/irr/CFileList.h wallpaperengine/irr/CFileList.cpp) target_link_libraries(wallengine ${X11_LIBRARIES} ${X11_Xxf86vm_LIB} ${OPENGL_LIBRARIES} ${GLUT_LIBRARIES} ${ZLIB_LIBRARIES} ${IRRLICHT_LIBRARY} ${LZ4_LIBRARY}) \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..be43454 --- /dev/null +++ b/README.md @@ -0,0 +1,72 @@ +# 1. Disclaimer +**This is an educational project**. Our main focus is to learn how Irrlicht Engine works and provide examples of usage of as much aspects of it as possible. We are not responsible for what others do with the source code downloaded from this project. + +# 2. What is this project all about? +This projects aims to reproduce the background functionality of Wallpaper Engine on Linux systems. Simple as that. + +# 3. What is Wallpaper Engine? +Wallpaper Engine is a software designed by [Kristjan Skutta](https://store.steampowered.com/search/?developer=Kristjan%20Skutta&snr=1_5_9__400) that provides live wallpaper functionality to Windows Systems, allowing It's users to animate their own backgrounds and sharing their own creations. You can find more about it on their [Steam page](https://store.steampowered.com/app/431960/Wallpaper_Engine/) + +# 4. Compilation requirements +- OpenGL 2.1 support +- CMake +- Irrlicht +- LZ4 +- ZLIB + +# 5. How to use +## 5.1. Pre-requirements +In order to properly use this software you'll need to own an actual copy of Window's Wallpaper Engine as it contains some basic assets on which most of the backgrounds are based on. +The only way to get those assets is to install the Windows version trough Steam. Luckily you don't really need a Windows OS for that. Using the Linux client should be enough to force the download. + +## 5.2. Extracting needed assets +Once Wallpaper Engine is downloaded open the installation folder (usually on C:\Program Files (x86)\Steam\steamapps\common\wallpaper_engine). Here you'll see the main folders of Wallpaper Engine. The folder we're interested in is the one named "assets". + +![folder](docs/images/screenshot_folder.png) + +All the folders we see must be compressed in a single zip file for the project to load them: + +![compression](docs/images/zip.png) + +The zip must be named "assets.zip" and placed on the same folder as the directory where the project is going to be run from. + +## 5.3. Compilation steps +The project is built on CMake as build engine. First we need to create the directory where the build will be stored and get into it: + +``` +mkdir build +cd build +``` + +Once the folder is created and we're in it, cmake has to generate the actual Makefiles. This can be done this way +``` +cmake .. +``` +Take a closer look at the CMake output, if you miss any library CMake will report the missing libraries so you can install them either trough your package manager or manually in your system. + +Finally we can compile the project to generate the actual executable +``` +make +``` + +**REMEMBER: The assets.zip file has to be at the same folder as the executable** + +## 5.4. Running a background +Currently both compressed and uncompressed backgrounds are supported. + +#### 5.4.1. Running compressed backgrounds +Compressed backgrounds are actually two separate files. One named "project.json" and another called "scene.pkg". These two files are important as one contains the background's information and the second one contains the needed assets for it. For the program to properly detect them we'll use the ```--pkg``` parameter, which will specify the folder where those two files are stored. +``` +./wallengine --pkg folder +``` + +#### 5.4.2. Running uncompressed backgrounds +Uncompressed backgrounds are just plain folders including all the resources and scene information all jumbled together. At least a project.json and a scene.json must exists for the background to even start loading. For the program to properly detect them we'll use the ```--dir``` parameter, which will specify the folder where the background itself is stored. +``` +./wallengine --dir folder +``` + +###### Example background +This was the first background to even be compatible with the software. And It's not 100% compatible yet. Both textures and shaders are properly loaded, but there are still particles missing. + +![example](docs/images/example.gif) \ No newline at end of file diff --git a/docs/images/example.gif b/docs/images/example.gif new file mode 100644 index 0000000..5ed7f9f Binary files /dev/null and b/docs/images/example.gif differ diff --git a/docs/images/screenshot_folder.png b/docs/images/screenshot_folder.png new file mode 100644 index 0000000..8387e34 Binary files /dev/null and b/docs/images/screenshot_folder.png differ diff --git a/docs/images/zip.png b/docs/images/zip.png new file mode 100644 index 0000000..51d6db9 Binary files /dev/null and b/docs/images/zip.png differ diff --git a/docs/TEXTURE_FORMAT.md b/docs/textures/TEXTURE_FORMAT.md similarity index 100% rename from docs/TEXTURE_FORMAT.md rename to docs/textures/TEXTURE_FORMAT.md diff --git a/main.cpp b/main.cpp index f668875..8ccc12b 100644 --- a/main.cpp +++ b/main.cpp @@ -1,10 +1,10 @@ #include #include #include -#include #include #include #include +#include #include "wallpaperengine/shaders/compiler.h" #include "wallpaperengine/project.h" @@ -66,13 +66,19 @@ int init_irrlicht() void preconfigure_wallpaper_engine () { - wp::config::path::base = wp::irrlicht::device->getFileSystem ()->getAbsolutePath ("../"); - wp::config::path::resources = wp::config::path::base + "/res"; - wp::config::path::shaders = wp::config::path::resources + "/shaders"; + // load the assets from wallpaper engine + wp::irrlicht::device->getFileSystem ()->addFileArchive ("assets.zip", true, false); + + // register custom loaders + wp::irrlicht::driver->addExternalImageLoader (new irr::video::CImageLoaderTex ()); + wp::irrlicht::device->getFileSystem ()->addArchiveLoader (new CArchiveLoaderPkg (wp::irrlicht::device->getFileSystem ())); } int main (int argc, char* argv[]) { + int mode = 0; + std::string path; + // parse the integer if it exists if (argc >= 1) { @@ -81,7 +87,45 @@ int main (int argc, char* argv[]) ss >> WinID; } - printf ("Initializing X11 to %d\n", WinID); + int option_index = 0; + + static struct option long_options [] = { + {"win", required_argument, 0, 'w'}, + {"pkg", required_argument, 0, 'p'}, + {"dir", required_argument, 0, 'd'}, + {nullptr, 0, 0, 0} + }; + + while (true) + { + int c = getopt_long (argc, argv, "w:p:d:", long_options, &option_index); + + if (c == -1) + break; + + switch (c) + { + case 'w': + if (optarg) + WinID = atoi (optarg); + break; + + case 'p': + mode = 1; + path = optarg; + break; + + case 'd': + mode = 2; + path = optarg; + break; + + default: + break; + } + } + + printf ("Initializing irrlicht to WindowID %d\n", WinID); if (init_irrlicht()) { @@ -90,22 +134,35 @@ int main (int argc, char* argv[]) preconfigure_wallpaper_engine (); - // do_decompress (); - irr::io::path _wp_engine_folder = "/home/almamu/Development/tmp/nier__automata_-_become_as_gods_edition/"; - irr::io::path _wp_project_file = _wp_engine_folder + "project.json"; + irr::io::path wallpaper_path; + irr::io::path project_path; + irr::io::path scene_path; - // load the assets folder from wallpaper engine - wp::irrlicht::device->getFileSystem ()->addFileArchive ("../assets.zip", true, false); + switch (mode) + { + // pkg mode + case 1: + wallpaper_path = wp::irrlicht::device->getFileSystem ()->getAbsolutePath (path.c_str ()); + project_path = wallpaper_path + "project.json"; + scene_path = wallpaper_path + "scene.pkg"; + break; + + // folder mode + case 2: + wallpaper_path = wp::irrlicht::device->getFileSystem ()->getAbsolutePath (path.c_str ()); + project_path = wallpaper_path + "project.json"; + break; + + default: + break; + } // set our working directory - wp::irrlicht::device->getFileSystem ()->changeWorkingDirectoryTo (_wp_engine_folder); + wp::irrlicht::device->getFileSystem ()->changeWorkingDirectoryTo (wallpaper_path); - // register custom loader - wp::irrlicht::driver->addExternalImageLoader (new irr::video::CImageLoaderTex ()); - wp::irrlicht::device->getFileSystem ()->addArchiveLoader (new CArchiveLoaderPkg (wp::irrlicht::device->getFileSystem ())); // wp::irrlicht::device->getFileSystem ()->addFileArchive (_wp_engine_folder + "scene.pkg", true, false); // add the pkg file to the lookup list - wp::project* wp_project = new wp::project (_wp_project_file); + wp::project* wp_project = new wp::project (project_path); if (wp_project->getScene ()->isOrthogonal() == true) { diff --git a/wallpaperengine/config.cpp b/wallpaperengine/config.cpp deleted file mode 100644 index b4cc2b0..0000000 --- a/wallpaperengine/config.cpp +++ /dev/null @@ -1,15 +0,0 @@ -// -// Created by almamu on 6/07/18. -// - -#include "config.h" - -namespace wp -{ - namespace config - { - irr::io::path path::resources; - irr::io::path path::base; - irr::io::path path::shaders; - } -} \ No newline at end of file diff --git a/wallpaperengine/config.h b/wallpaperengine/config.h deleted file mode 100644 index 0da59f1..0000000 --- a/wallpaperengine/config.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef WALLENGINE_CONFIG_H -#define WALLENGINE_CONFIG_H - -#include -#include - -namespace wp -{ - namespace config - { - class path - { - public: - static irr::io::path resources; - static irr::io::path base; - static irr::io::path shaders; - }; - }; -} - - -#endif //WALLENGINE_CONFIG_H diff --git a/wallpaperengine/shaders/compiler.cpp b/wallpaperengine/shaders/compiler.cpp index 9f09a8c..6257922 100644 --- a/wallpaperengine/shaders/compiler.cpp +++ b/wallpaperengine/shaders/compiler.cpp @@ -3,9 +3,6 @@ #include #include -// system configuration -#include - // filesystem #include diff --git a/wallpaperengine/shaders/compiler.h b/wallpaperengine/shaders/compiler.h index 7d67f59..e14d90e 100644 --- a/wallpaperengine/shaders/compiler.h +++ b/wallpaperengine/shaders/compiler.h @@ -35,6 +35,14 @@ namespace wp int size; }; + struct ShaderParameters + { + char* variableName; + void* defaultValue; + void* range [2]; + char* type; + }; + /** * Types of shaders */ @@ -191,9 +199,9 @@ namespace wp */ Type m_type; /** - * The file resolver to be used by the compiler to load the files + * Tha parameters the shader needs */ - wp::fs::utils m_resolver; + std::vector m_parameters; }; } }