A very minimal game application can be created that will print the text "Hello, World!" in the upper left of the screen.
In this series of tutorials, we will guide you through setting up a personal NeL project, creating an initial main.cpp file, configuring CMake, and initializing the NeL driver to open up a blank window with a basic game loop. After that, you will learn how to create a simple text renderer, render the text, and position it on the screen.
This tutorial assumes you've already succeeded in building the NeL source code using Visual Studio on Windows or using GCC on Linux.
Create a new CMakeLists.txt file in the personal folder that you can find in the source code git repository. This file will contain the settings used to generate the application executable.
FILE(GLOB SRCS *.cpp)
FILE(GLOB HDRS *.h)
FILE(GLOB RECS *.rc)
SOURCE_GROUP("" FILES ${SRCS} ${HDRS} ${RECS})
ADD_EXECUTABLE(my_game ${SRCS} ${HDRS} ${RECS})
TARGET_LINK_LIBRARIES(my_game nelmisc nel3d nelsound)
NL_DEFAULT_PROPS(my_game "My Game")
NL_ADD_RUNTIME_FLAGS(my_game)
INSTALL(TARGETS my_game RUNTIME DESTINATION ${NL_BIN_PREFIX} COMPONENT personal)
Inside the same folder, create a new file named main.cpp. This file will serve as the entry point for your project.
#include <nel/misc/types_nl.h>
#include <nel/misc/app_context.h>
#include <nel/misc/debug.h>
using namespace std;
using namespace NLMISC;
// Main game class
class CMyGame
{
public:
CMyGame();
~CMyGame();
void run();
private:
// ...
};
// Initialize game resources
CMyGame::CMyGame()
{
// Initialize the NeL driver, and other required components here
// ...
}
// Release game resources
CMyGame::~CMyGame()
{
// Release resources here
// ...
}
// Main loop
void CMyGame::run()
{
// Implement the main loop here
// ...
}
// Main function
int main(int argc, char *argv[])
{
// Create the application context
CApplicationContext applicationContext;
// Run the game
CMyGame myGame;
myGame.run();
return EXIT_SUCCESS;
}
This source files sets up the application singleton context for NeL, and prepares an empty game class to get started.
From the build folder, using your command line terminal, reconfigure CMake with the additional -DWITH_PERSONAL=ON build setting. This will regenerate the build projects.
cmake -DWITH_PERSONAL=ON ..
Or use the CMake GUI to add the option.
Open the RyzomCore.sln file in the build folder. Right click on the "My Game" project, click on Set as Startup Project. Then right click again, and open the Properties panel. Under the Debugging header, open the <Edit> window for the Environment option, and fill in the directories containing the binaries from the externals package. Then push OK and save the project. This way the executable will find all the libraries without having to copy them manually.
PATH=C:\2022q2_external_v143_x64\zlib\bin;C:\2022q2_external_v143_x64\curl\bin;C:\2022q2_external_v143_x64\openssl\bin;C:\2022q2_external_v143_x64\libjpeg\bin;C:\2022q2_external_v143_x64\libpng\bin;C:\2022q2_external_v143_x64\libxml2\bin;C:\2022q2_external_v143_x64\freetype\bin;C:\2022q2_external_v143_x64\ogg\bin;C:\2022q2_external_v143_x64\vorbis\bin;C:\2022q2_external_v143_x64\openal-soft\bin;C:\2022q2_external_v143_x64\lua\bin;C:\2022q2_external_v143_x64\luabind\bin;C:\2022q2_external_v143_x64\mariadb-connector-c\bin;C:\2022q2_external_v143_x64\assimp\bin;C:\2022q2_external_v143_x64\ffmpeg\bin;C:\2022q2_external_v143_x64\gles\bin;C:\2022q2_external_v143_x64\msquic\bin;C:\2022q2_external_v143_x64\protobuf\bin;C:\2022q2_external_v143_x64\squish\bin;C:\2022q2_external_v143_x64\qt5\bin;C:\2022q2_external_v143_x64\qt5\plugins;%PATH%
QT_PLUGIN_PATH=C:\2022q2_external_v143_x64\qt5\plugins
Switch to the Debug build target, and hit the Build Solution button to build your project.
Just run Ninja to build your new project.
ninja