mkdir tut01 cd tut01
Now, make a source file, "main.cpp", with the following code:
#include "mortic/mortic.h" // A simple main function int main() { // Default and Override configuration... mortic::IConfigSet defaults; mortic::IConfigSet overrides; // Make sure that we open up in windowed mode defaults.setOption("VideoManager", "fullscreen", "0"); // Make sure that we always log to /log.html overrides.setOption("LogManager", "file", "/log.html"); // Finally, we start mortic mortic::IRoot* root = mortic::createRoot("settings.xml", &defaults, &overrides); // Run in a loop until we close the window. while (root->run()); // Destroy our root and clean up. mortic::destroyRoot(root); return 0; }
c++ -I../extern/irrlicht/include -lmortic main.cpp -o main
./main
The first thing you should look at is the mortic console. To get to it, press ESC in the window. A small blue window should pop down that says "Mortic Console". That's it! This thing is like an interactive Python interpreter, except it has access to all of mortic's internals. This thing is very useful for messing around with mortic.
The mortic root you made in the C++ code (more about roots later) is accessable by "root" from python.
Another thing you should look at is the log file. Close the window and open up the new file that was just made, "log.html". Although most loggers only write plain text, mortic's logger writes HTML files for added readability. When you have seen enough of your log file, close it and open "settings.xml" in a text editor.
This file is the configuration file for your program. In it, you can see all of the options available for you to mess with. An example file is given below:
<MorticConfig> <VideoManager> <fullscreen>0</fullscreen> <width>640</width> <height>480</height> <bits>16</bits> <vsync>0</vsync> </VideoManager> <LogManager> <file>/log.html</file> <level>notify</level> </LogManager> </MorticConfig>
<MorticConfig> <VideoManager> <fullscreen>0</fullscreen> <width>800</width> <height>600</height> <bits>16</bits> <vsync>0</vsync> </VideoManager> <LogManager> <file>/log.html</file> <level>debug</level> </LogManager> </MorticConfig>
Sure enough, when you run your program again, it pops up a bigger window, and also spews out a lot more messages to "log.html". Try messing around with some other options and see what happens. If you get stuck in fullscreen mode, just pull down the mortic console and type "quit()" to quit the program.
#include "mortic/mortic.h"
int main()
{
Now comes the start of mortic-specific code. When we want to start the engine, we have to give it three things: the name of the configuration file, a list of default configuration options, and a list of override configuration options. The defaults are used when the options aren't found in the configuration file, and the overrides are used to make sure that some values can not be configured. These configuration lists are stored in the class "mortic::IConfigSet". Lets declare a few to hold our options:
mortic::IConfigSet defaults; mortic::IConfigSet overrides;
defaults.setOption("VideoManager", "fullscreen", "0");
overrides.setOption("LogManager", "file", "/log.html");
Now that we have all of our options set, we are ready to start mortic:
mortic::IRoot* mortic::createRoot("settings.xml", &defaults, &overrides);
Now that we have our root, we start running it. Every time you call IRoot::run(), two things happen. First, it goes through one frame of running. You should call this every frame. Second, it checks to see if it should keep running. This function returns false if the window is closed, or something else happens that causes mortic to want to quit. Thus, this little while loop works fine! It calls run() as often as possible, but stops and quits as soon as it returns false!
while (root->run());
After that bit, it's time to quit. We do this by destroying the root and returning from main():
mortic::destroyRoot(root); return 0; }
using namespace mortic;