LiteFX 0.3.1.2022
Computer Graphics Engine
|
This guide demonstrates the steps that are required to setup a simple application that uses the LiteFX engine. It also shows you how to integrate shaders and assets into your build process.
LiteFX makes heavy use of CMake for building applications. Using the engine is straightforward, if your application uses CMake too. This guide will only focus on explaining how to setup a new project using CMake. Other build systems might work similar. In fact, all required sources are available from the binary release or manual build. For details about how to perform a manual build, read the installation notes.
Before we start, we need to make sure that your application can access the engine and it's dependencies. Start of by downloading the latest release and extract and copy it to a location you prefer.
The engine on itself does, however, require you to install its dependencies too. There are several ways to do this:
FindXXX.cmake
files to locate the dependencies. However, this process is convoluted, tedious and error-prone and thus not further described in this guide.Let's start creating our project. Create a new directory and within it, create the following files:
Apart from the CMakeLists.txt file, we are not going to write any code in this guide. The next guide will walk you through the steps required to write a simple rendering application.
Go ahead and open the CMakeLists.txt file with any text editor. Copy the following code into the file:
Replace the ...
in line 5 with the directory, you've installed all your dependencies and the engine to. If you have installed LiteFX to another directory, add the following line below SET(CMAKE_PREFIX_PATH "...")
:
Again, replace the ...
with the directory, you've placed the LiteFX release to.
Next, we have to ensure, that the dynamic library files (i.e. the DLL-files) for all dependencies are copied to the build directory. Otherwise your app will not run properly. LiteFX provides a list of all dependencies in the LITEFX_DEPENDENCIES
variable. Add the following code to the bottom of your CMakeLists.txt file to add a copy command for the build:
This loop looks complicated at first, but all it does is to look for the right library file, depending on the build configuration (Debug
or Release
) and copy the proper file into the build directory in a post-build event.
If you choose to use vcpkg, then the CMakeLists.txt file will look slightly different. If you want to go ahead with the manual installation, you can skip this section.
Again, replace the ...
in line 4 with the path to the vcpkg installation and set the LiteFX_DIR
in line 9 to the release location. Unfortunately, LiteFX does not currently have its dedicated vcpkg-port, that's why this directory needs to be specified. Before we continue, create another file in the project directory and call it vcpkg.json. This file is called manifest file and is used by vcpkg to find the dependencies and install them when the project is configured later. Copy the following code to the manifest file:
The next thing we need to do is letting CMake configure our project. Open a command line interface and navigate to your project directory. Run the following command to configure your project and write the build to the out/build/ subdirectory:
Note that there are other ways to do this step. For example, Visual Studio's CMake integration is very straightforward and should be used, if you are working with Visual Studio anyway.
The next step is to write the actual code and is described in the quick start guide. In order to compile your application after you've changed the code, you can run the following command:
Currently this build will fail, because we have not yet written any code.
During development you naturally have to work with shaders. LiteFX allows you to easily integrate shader sources into your build tree using CMake. You can use the ADD_SHADER_MODULE
function to define a shader. The TARGET_LINK_SHADERS
function can then be used to define a dependency to the shader module for your project. For more information, refer to the project wiki.
Similar to shaders, you may want to integrate assets into your build process. Using LiteFX, you can define asset directories using the TARGET_ADD_ASSET_DIRECTORY
function. This function will define a sub-directory that can be used by your executable to locate assets. For more information, refer to the project wiki.