@c -*-texinfo-*-
@node HOWTO Pixmaps, HOWTO Recording Movies, HOWTO Clicking on Objects, HOWTO
@subsection Loading Images for Pixmaps
@cindex @code{csSimplePixmap}
@cindex loading images
@cindex @sc{vfs}
@cindex @code{iImageIO}
@cindex @code{iImage}

This section describes how you can load an image and use it on a pixmap.  A
pixmap is a small graphics class that can be used independently from the
engine.  It may be useful, for instance, to draw a logo on screen or for a
@dfn{heads-up-display} (@sc{hud}).

@subsubheading Getting the Image Loader Plugin

To load an image you need the image loader plugin. There are two
ways to make sure you have this plugin in your application. You can put
a line in your configuration file like this:

@example
System.Plugins.iImageIO = crystalspace.graphic.image.io.multiplex
@end example

Or you can add the following line to the call to
@code{csInitializer::RequestPlugins()} in your @code{main()} function:

@example
CS_REQUEST_IMAGELOADER,
@end example

To actually use the image loader in your application you need to ask the
shared-object registry for a handle to the image loader:

@example
csRef<iImageIO> imgldr = csQueryRegistry<iImageIO> (object_reg);
@end example

@subsubheading Loading the Image from @sc{vfs}

Next, you will probably want to load the image from @sc{vfs} (@pxref{VFS}).
This is accomplished by loading the image as raw data and then asking the image
loader to re-interpret the raw data as an actual @samp{iImage} resource.

@example
iGraphics3D* g3d = @dots{}
iTextureManager* txtmgr = g3d->GetTextureManager ();
csRef<iDataBuffer> buf = VFS->ReadFile ("/lib/mydata/test.jpg");
csRef<iImage> ifile = imgldr->Load (buf, txtmgr->GetTextureFormat ());
csRef<iTextureHandle> txt =
  txtmgr->RegisterTexture (ifile, CS_TEXTURE_2D);
@end example

This code first uses @sc{vfs} to load the image from the given @sc{vfs}
path. This will only load the image data. @sc{vfs} doesn't know how to parse
images. This is the responsibility of the image loader. This is what the
next line does. Here you give the loaded buffer to the image loader which
will return the loaded image with an @code{iImage} pointer.

Now you have to make sure the image becomes a texture that is usable for
drawing on screen. This is done with @code{txtmgr->RegisterTexture()}. Because
we are going to use the texture for a pixmap (which is 2D) we use the
@samp{CS_TEXTURE_2D} flag.

@subsubheading Using the Texture in a Pixmap

To create a pixmap using this texture you can simply do:

@example
csSimplePixmap* pixmap = new csSimplePixmap (txt);
@end example

@subsubheading Drawing the Pixmap

There are various ways to draw the pixmap. Check out the @sc{api} documentation
for more info. But here is one example:

@example
pixmap->DrawScaled (G3D, 10, 10, 400, 400);
@end example

This will draw the pixmap at location 10, 10 with dimension 400, 400.
If needed it will scale so that the pixmap really fits there.

@subsubheading Include Files

The include files useful for this section are:

@example
#include <cstool/cspixmap.h>
#include <igraphic/image.h>
#include <igraphic/imageio.h>
#include <ivideo/texture.h>
#include <ivideo/txtmgr.h>
#include <iutil/vfs.h>
@end example
