Sophie

Sophie

distrib > Mageia > 7 > i586 > media > core-release > by-pkgid > a2116f36018873d572acbcadddb8e994 > files > 26

clanlib0.8-docs-0.8.1-22.mga7.i586.rpm


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Getting started with ClanLib - ClanLib Game SDK</title>
<link rel="stylesheet" type="text/css" href="../../default.css">
</head>
<body style="background-color: #a4daea; color: black; margin: 1em 3em 1em 3em;">
<div style="border-style: solid; border-width:thin; border-color: black;">
<div style="background-color: white; color: black; padding: .3em 1em .3em 1em; border-bottom-style: dotted; border-bottom-width: 2px;">
<table cellspacing="0" cellpadding="0" border="0" width="100%">
<tr>
<td align="center">
<h1>
<a href="http://www.clanlib.org"><img style="border-style: none; padding-right: 130px;" src="../../gfx/clanlib.png" alt="ClanLib"></a>
</h1>
</td>
</tr>
</table>
<!--<div class="menu">
  <a href="index.html">News</a>
  <a href="intro.html">About</a>
  <a href="download.html">Download</a>
  <a href="cvs.html">CVS</a>
  <a class="active" href="docs.html">Docs</a>
  <a href="games.html">Games</a>
  <a href="contact.html">Contact</a>
  <a href="links.html">Links</a>
</div>-->
</div>
<div style="background-color: white; padding: 1em 3em 1em 3em;">
<!-- clanlib header end -->

<div style="border-bottom-style: dotted;  border-bottom-width: 1px; margin-bottom: 1em;"><h2>Getting started with ClanLib</h2></div>



<p>This document shows how to write a very basic ClanLib application, 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. Finally it explains how to trace errors and handle exceptions in ClanLib.</p>

<div style="border-bottom-style: dotted;  border-bottom-width: 1px;"><h3>The CL_ClanApplication Interface</h3></div>

<p>We will start at the first steps needed to use ClanLib: initialization of
the library and the application. Most libraries do 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>

<ul><pre><font face="Arial,Courier New,Courier">void main()
{
	library_init();
	// run game
	library_deinit();
}
</font></pre></ul>

<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 encapsulate 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>

<ul><pre><font face="Arial,Courier New,Courier">
#include &lt;ClanLib/core.h&gt;
#include &lt;ClanLib/application.h&gt;

class MyClanLibApplication : public CL_ClanApplication
{
public:
	virtual int main(int argc, char **argv)
	{
		CL_SetupCore setup_init;
		
		// Insert game code here
		
		return 0;
	}
} app;
</font></pre></ul>

<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>

<div style="border-bottom-style: dotted;  border-bottom-width: 1px;"><h3>Initializing components</h3></div>

<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 <a href="../Reference/html/CL_SetupCore.html">CL_SetupCore</a> class. </p>

<p>Each library in ClanLib has such a class. The clanGL library has
<a href="../Reference/html/CL_SetupGL.html">CL_SetupGL</a>, clanGUI has
<a href="../Reference/html/CL_SetupGUI.html">CL_SetupGUI</a>, and so on.
You <i>must</i> create these classes before using the respective components in your
program. Make sure they don't go out of scope until your program is ending.</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>

<ul><pre><font face="Arial,Courier New,Courier">
#include &lt;ClanLib/core.h&gt;
#include &lt;ClanLib/display.h&gt;
#include &lt;ClanLib/gl.h&gt;
#include &lt;ClanLib/sound.h&gt;

class MyClanLibApplication : public CL_ClanApplication
{
public:
	virtual int main(int argc, char** argv)
	{
		CL_SetupCore setup_core;
		CL_SetupDisplay setup_display;
		CL_SetupGL setup_gl;
		CL_SetupSound setup_sound;
		
		// run game.

		return 0;
	}
} app;
</font></pre></ul>

<div style="border-bottom-style: dotted;  border-bottom-width: 1px;"><h3>Creating a simple Makefile for Linux</h3></div>

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

<div style="border-bottom-style: dotted;  border-bottom-width: 1px;"><h3>Creating a ClanLib project in Visual C++</h3></div>

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

<div style="border-bottom-style: dotted;  border-bottom-width: 1px;"><h3>Creating a ClanLib project in Borland C++</h3></div>

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

<!-- clanlib footer begin -->
<div style="margin-top: 0em; text-align: center; color: #a0a0a0; border-top-style: dotted; border-top-width: 1px;">
              Questions or comments, write to the <a href="http://clanlib.org/contact.html">ClanLib mailing list</a>.
            </div>
</div>
</div>
</body>
</html>