Book Image

Lua Game Development Cookbook

By : Mario Kasuba, Mário Kašuba
Book Image

Lua Game Development Cookbook

By: Mario Kasuba, Mário Kašuba

Overview of this book

Table of Contents (16 chapters)
Lua Game Development Cookbook
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Loading images with SDL_image


This recipe will show you how to load images from various file formats. SDL_image supports the file formats BMP, CUR, GIF, ICO, JPG, LBM, PCX, PNG, PNM, TGA, TIF, XCF, XPM, and XV. SDL_image is a part of the LuaSDL module.

All images are loaded into the new surface object. File formats with support for transparent pixels (it's not the same as the alpha channel) would have set the color key attribute on the surface.

Getting ready

The SDL_image library depends on third-party libraries to load JPEG and PNG files. Make sure that you have the libjpeg, libpng, and zlib libraries installed. SDL_image doesn't require any additional initialization. LuaSDL handles this internally.

How to do it…

There are two ways of loading images:

  • Loading an image file directly to surface: This method uses the SDL.SDL_IMG_Load function, where the only parameter is the image filename. If there is such a file and it is accessible to the application, SDL.SDL_IMG_Load will try to guess a file...