Game Development Reference
In-Depth Information
Creating images
We will explore ways of creating and loading images before we jump into textures. Many
of the functions we see in the Image class also exist in Texture . The following code
demonstrates how to create a 50 x 50 image and fill it with red color:
The first two arguments of the Image::create() function represent the width and
height of the image, and the last argument is the color fill for the image. By default, the col-
or is set to black with alpha 255.
Images can also be created by passing an array of pixels directly. The array must hold ele-
ments of the type Uint8 , which is a single byte of memory. Since Image::create()
requires the colors to be in an RGBA format, we need to make sure that the array holds ex-
actly 4 bytes for each color (1 byte per color component). Every consecutive 4 bytes rep-
resents a pixel of the image grid, which is laid out as rows by columns. Here is an example
of how this can be done:
Search WWH ::




Custom Search