Difference between revisions of "Images"
Line 17: | Line 17: | ||
== See Also == | == See Also == | ||
* [[Resource Loading]] | * [[Resource Loading]] | ||
+ | |||
+ | [[Category:Images]] [[Category:Graphics]] |
Revision as of 16:42, 8 August 2013
Images are the most primitive drawing tool within Slick. They are the root of most of utilities for rendering. Each image will draw a rectangular area on the screen filled with some pixels based on either a generated source (see ImageBuffer) or a image loaded from disk.
Slick currently uses java's ImageIO to load images so supports, PNG, GIF and JPG. It also supports TGA through a pure java loader which is generally much faster than using ImageIO. However, the TGA must be non-compressed and 32 bit to be loaded correctly. Note that of course resources are generally placed in JAR files and as such TGA compresses down in this context in a similar magnitude to PNG.
As with most things in Slick images are currently rendered in the simplest manner possible, using OpenGL immediate mode. This is not the most efficient manner and hence this is subject to change at a later date (should a need arise).
Note that fonts, sprite sheets and particles all rely on the basic image class. It's also worth remember that any given texture (or extenal image) is loaded only once and hence no caching is required on the developers side. This also means that sub-images and references to the original data so memory is not duplicated. As a side effects images are considered non-mutable - i.e. they can not be changed - which may have invalidated another references rendering.
Usage
Images can be loaded and used simply by construction. To load an image ready for use the following code could be used at initialization:
Image img = new Image("res/myimage.png");
The image can either be in the classpath (for webstart) or on the file system (for local testing).