File: getting_started.xml

package info (click to toggle)
clanlib 0.5.4-1-6
  • links: PTS
  • area: main
  • in suites: woody
  • size: 10,320 kB
  • ctags: 10,893
  • sloc: cpp: 76,056; xml: 3,281; sh: 2,961; perl: 1,204; asm: 837; makefile: 775
file content (137 lines) | stat: -rw-r--r-- 4,005 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<xml>
<head>
<title>Getting started with ClanLib</title>
<eyecolor>yellow</eyecolor>
</head>
<body>

<h2>Abstract</h2>

<p>This 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.</p>

<h2>The CL_ClanApplication Interface</h2>

<p>Welcome 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.:</p>

<code>
void main()
{
	library_init();
	// run game
	library_deinit();
}
</code>

<p>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.</p>

<p>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:</p>

<code>

#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;
</code>

<p>There has to be <i>one</i> single instance of this class - otherwise
ClanLib isn't able to locate the class, and thus cannot invoke the main
function.</p>

<p>This can somewhat be compared to the Applet class in Java, and CWinApp in
Microsoft's Foundation Classes (MFC).</p>

<h2>Initializing components</h2>

<p>ClanLib 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 <codelink>CL_SetupCore</codelink> class: </p>

<code>
class CL_SetupCore
{
	static void init();
	static void deinit();
};
</code>

<p>Each library in ClanLib has such a class. The clanGL library has
<codelink>CL_SetupGL</codelink>, clanGUI has
<codelink>CL_SetupGUI</codelink>, 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 <i>must</i> call those before using the respective components in your
program, and call the deinit-function when the program ends.</p>

<p>If you need to use the display and sound parts of ClanLib, but not the
network, you could do something like this:</p>

<code>

#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;
}
</code>

<h2>Creating a simple Makefile for Linux</h2>

<p>Read the file INSTALL.linux in the ClanLib root directory for
specifix details on how to use ClanLib under Linux.</p>

<h2>Creating a ClanLib project in Visual C++</h2>

<p>Read the file INSTALL.win32 in the ClanLib root directory for
specific details on how to use ClanLib with Microsoft Visual C++ 6.0.</p>

<h2>Creating a ClanLib project in Borland C++</h2>

<p>Read the file INSTALL.borland in the ClanLib root directory for
specific details on how to use ClanLib with Borland C++.</p>

</body>
</xml>