Sophie

Sophie

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

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>Loading graphics - 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>Loading graphics</h2></div>



<div style="border-bottom-style: dotted;  border-bottom-width: 1px;"><h3>Before you load graphics</h3></div>

<p>Before loading any graphics in ClanLib, you <b>MUST</b> have created a displaywindow first.
When surfaces are created, they are converted to the most optimal format for fast
blitting to the display, and therefore you need a displaywindow before loading any graphics.</p>

<div style="border-bottom-style: dotted;  border-bottom-width: 1px;"><h3>Loading from files</h3></div>

<p>Most ClanLib games will usually use resources to load its graphics, but
we will start showing how the inner parts of the resource manager loads its
graphics. Hopefully this should make it more clear how the whole stuff
works.</p>

<p>To construct a surface or texture in ClanLib, we first need to load it
into a surface provider. There are surface providers for many common image
formats, including: CL_PCXProvider, CL_TargaProvider, CL_PNGProvider and
CL_JPEGProvider.</p>

<p>To use these providers, simple create an instance of it, eg.</p>

<ul><pre><font face="Arial,Courier New,Courier">// Create a provider:
CL_TargaProvider provider("image.tga");

// Load it:
CL_Surface surface(provider);
</font></pre></ul>

<p>Luckily, ClanLib provides a shortcut for the lazy among us.
It can automatically figure out which provider to use based on the
file-extension. Use it like this:</p>

<ul><pre><font face="Arial,Courier New,Courier">CL_Surface surface2("image.tga");
</font></pre></ul>

<div style="border-bottom-style: dotted;  border-bottom-width: 1px;"><h3>Loading from resources</h3></div>

<p>Although the above loading mechanism in itself is quite simple, it is
often far better to seperate the description of an image from the actual
game code. Instead of specifying an image by its filename and type, you use
an name making more sense for the game code.</p>

<ul><pre><font face="Arial,Courier New,Courier">CL_ResourceManager resources("resources.xml");

CL_Surface surface("InGame/Level1/background", &resources);
</font></pre></ul>

<p>The image may be in any format supported by the ClanLib surface
providers, and the resource description may include transparency, subarrays
and other fancy stuff. The resources.xml file includes a description of the
resource that may look like this:</p>

<ul><pre><font face="Arial,Courier New,Courier">&lt;resources&gt;
	&lt;section name="InGame"&gt;
		&lt;section name="Level1"&gt;
			&lt;surface name="background" file="background1.tga" /&gt;
			&lt;surface name="walking_man" file="man.pcx" tcol="0,1,2,3" /&gt;
		&lt;/section&gt;
	&lt;/section&gt;
&lt;/resources&gt;
</font></pre></ul>

<p>As you can probably see, the game code no longer needs to know how the
resource is physically loaded. And it is possible to change the image
without recompiling the application.</p>

<p>The resource manager may also be attached to something else than physical
files, it may be loading them from a network server, or a zipfile. The nice
thing is that the game code does not need to know.</p>

<p>If you want more information about resources, have a look at the <a
href="resources-1.html">resource overview</a>.</p>

<!--
<div style="border-bottom-style: dotted;  border-bottom-width: 1px;"><h3>Creating from scratch</h3></div>

<p>NOTE THAT CANVAS IS NOT FULLY TESTED IN ClanLib 0.7!</p>

<p>If you need to create an image from scratch, or want to compose an image
from multiple other images, or modify an image in some way, ClanLib provides
a surface type called CL_Canvas. At construction time, you tell how large
and in what format the canvas should be in, and then afterwards you modify
the contents of it by drawling lines, boxes, surfaces on it.</p>

<ul><pre><font face="Arial,Courier New,Courier">// Load an image:
CL_Surface *surf = new CL_Surface("image.tga");

// Create a canvas, size 320x200, default image format:
CL_Canvas *canvas = new CL_Canvas(CL_Size(320, 200));

// Draw a line on it:
canvas-&gt;draw_line(0,0,100,100);

// Draw the surface on it:
surf-&gt;draw(10, 10, canvas);

// Construct a surface from it:
CL_Surface *canvas_surf = CL_Surface::Create(canvas, true);
</font></pre></ul>
-->

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