Getting started with ClanLibAbstractThis document shows how to write a very basic ClanLib appliation, using the CL_ClanApplication interface. It explains why a global instance of this class is needed and how to initialize the different subsystems/components in ClanLib (using the CL_System and CL_Settings classes). Finally it explains how to trace errors and handle exceptions in ClanLib. The CL_ClanApplication InterfaceWelcome to the ClanLib overview documentation. We will start at the first steps needed to use ClanLib: initialization of the library and the application. Most libraries does this by requiring an application to call some kind of init function before the library is used, and a deinit function at the end of the application. Eg.: void main() { library_init(); // run game library_deinit(); } However, ClanLib doesn't use this strategy for one important reason: ClanLib runs on a lot of platforms. Some of these platforms do not use the traditional main() initialization method. Windows is an example where WinMain() is used instead. Often ClanLib need to use the parameters to these alternative main() functions, and thus requires a very platform dependent initialization. We have solved the problem by making ClanLib itself incapsulate the real main() function, and then call the ClanLib application when it is done with its initialization. The resulting main() "function" in ClanLib looks like this: #include <ClanLib/core.h> #include <ClanLib/application.h> class MyClanLibApplication : public CL_ClanApplication { public: virtual char *get_title() { return "MyApplication"; } virtual int main(int argc, char **argv) { CL_SetupCore::init(); // Insert game code here CL_SetupCore::deinit(); return 1; } } app; There has to be one single instance of this class - otherwise ClanLib isn't able to locate the class, and thus cannot invoke the main function. This can somewhat be compared to the Applet class in Java, and CWinApp in Microsoft's Foundation Classes (MFC). Initializing componentsClanLib is a large library and thus can be used for several purposes. Because of this, ClanLib doesn't initialize its components before asked to. This is done through the CL_SetupCore class: class CL_SetupCore { static void init(); static void deinit(); }; Each library in ClanLib has such a class. The clanGL library has CL_SetupGL, clanGUI has CL_SetupGUI, and so on. Since each of these libraries requires some initialization and shutdown code, the CL_SetupXXX classes always contain at least two functions, called init() and deinit(). You must call those before using the respective components in your program, and call the deinit-function when the program ends. If you need to use the display and sound parts of ClanLib, but not the network, you could do something like this: #include <ClanLib/core.h> #include <ClanLib/display.h> #include <ClanLib/sound.h> virtual int main(int argc, char** argv) { CL_SetupCore::init(); CL_SetupDisplay::init(); CL_SetupSound::init(); // run game. CL_SetupCore::deinit(); CL_SetupDisplay::deinit(); CL_SetupSound::deinit(); return 1; } Creating a simple Makefile for LinuxRead the file INSTALL.linux in the ClanLib root directory for specifix details on how to use ClanLib under Linux. Creating a ClanLib project in Visual C++Read the file INSTALL.win32 in the ClanLib root directory for specific details on how to use ClanLib with Microsoft Visual C++ 6.0. Creating a ClanLib project in Borland C++Read the file INSTALL.borland in the ClanLib root directory for specific details on how to use ClanLib with Borland C++. |