Note
It is recommended to out your project files under SaturnRingLib/Projects
Tip
It is more simple to copy a sample into the Projects folder and then add or change files as needed.
Your Project Folder.gitignoreMakefileThis makefile has configuration settings for SRL.compile.batcompiles the projectclean.batcleans the build directoryrun_with_mendafen.batruns the project inside mendafen emulatorsrc/contains your project source filescd/files to be placed on the final, burned CD. File such as TGA files, NYA files, etcBuildDrop/contains the final build ISO
Note
This tutorial assumes that a empty main.cxx file exists on the <project folder>/src folder.
All programs using SRL must use the srl.hpp header at the start.
#include <srl.hpp>Is is also recommended (but not mandatory), for legibility issues, to use the appropriate namespaces. SRL provides many datatypes designed to help with saturn development.
using namespace SRL::Types;
using namespace SRL::Math::Types;SRL program entry point is, as usual with C++ programs, the int main() function.
Before the use of any SRL function, it must be initialized via the SRL::Core::Initialize function. A SRL::Types::HighColor containing the color must be provided.
Tip
SRL already defines some colors that the programmer can use, without having to manually define its RGB values. For example SRL::Types::HighColor::Colors::Black for the black color. Now you can see why we define namespaces in order to ease the use of SRL defined types.
Important
SRL MUST be initialized before the use of any SRL functionality.
The code, so far, looks like this
#include <srl.hpp>
using namespace SRL::Types;
using namespace SRL::Math::Types;
int main()
{
SRL::Core::Initialize(HighColor::Colors::Black);
return 0;
}
Now that we have the SRL initialized, we can start using it.
We will begin how using the SRL::Debug class.
This class and its member functions are used to print information to the screen, and it's meant to aid in debugging tasks. In other words, you will be using it a lot :)
To print a text to the screen, the SRL::Debug::Print function is used. There are 2 overloads : one that allows the print a simple string, and another that is a variadic function that takes arguments in the same way as the classic printf() function.
Using this function can simply be done with :
SRL::Debug::Print(1,1, "Hello World");This should print the "Hello World" string at the x=1 ,y= 1 coordinates.
This will be the resulting program :
#include <srl.hpp>
// Using to shorten names for Vector and HighColor
using namespace SRL::Types;
using namespace SRL::Math::Types;
// Main program entry
int main()
{
SRL::Core::Initialize(HighColor::Colors::Black);
SRL::Debug::Print(1,1, "Hello World");
return 0;
}However this will not print anything on the screen.
Important
At the end of each frame the function SRL::Core::Synchronize() must be called. Otherwise nothing will be drawn at the end of the frame.
The correct, working program looks like :
#include <srl.hpp>
// Using to shorten names for Vector and HighColor
using namespace SRL::Types;
using namespace SRL::Math::Types;
// Main program entry
int main()
{
// Initialize library
SRL::Core::Initialize(HighColor::Colors::Black);
SRL::Debug::Print(1,1, "Hello World");
while(1)
{
SRL::Core::Synchronize();
}
return 0;
}To compile the project , in windows, you simple run the compile.bat in the project folder.
To run the project inside an emulator with run_with_mednafen.bat in the project folder.
On this short tutorial you learned that :
- To start using the library its recommended that you copy a sample program in the
samplesfolder into theProjectsfolder, and modify and add from there. This ensures the helper scripts and makefile are already in place. - Every SRL project must:
- Include
srl.hppheader - Initialize the SRL library before using any
SRLfunction - Call
SRL::Core::Synchronize();at the end of each frame
- Include
SRL::Debug::Print(int x, int y, char* text)can be used to print text into the screen.