Note: The Agar manual pages follow certain conventions, notably concerning function return values. Please read AG_Intro(3) first.
SYNOPSIS
#include <agar/core.h> #include <agar/gui.h> |
DESCRIPTION
|
The
AG_Surface structure describes a raster-based software graphics surface.
It supports all
packed pixel formats which encode pixels in 32-bit or less and allow components to be
retrieved by bitmasks.
Indexed (or
palletized) pixel formats up to 8-bit per pixel are also supported.
AG_Surface supports colorkey and alpha-blending (with an alpha channel or per-surface alpha setting). Surfaces may define destination clipping rectangles for operations such as AG_SurfaceBlit(). |
INITIALIZATION
|
The AG_SurfaceNew() function allocates and initializes a new AG_Surface of the specified dimensions w, h (given in pixels). fmt is a pointer to a AG_PixelFormat structure describing the way pixels are to be encoded in memory (see PIXEL FORMATS section below). The pixel data is left uninitialized. Acceptable values for type include:
Acceptable flags include:
The AG_SurfaceEmpty() function creates a new 0x0 pixel surface. Blitting such an empty surface is a no-op. AG_SurfaceStdRGB() and AG_SurfaceStdRGBA() create a surface in the recommended standard format, as determined by Agar on initialization time. Usually, this is a packed-pixel format with an alpha component. The AG_SurfaceIndexed() function creates a new surface of w by h pixels using indexed pixel format. This involves the allocation of a palette. The size of this palette is determined by bitsPerPixel. All entries in the palette are initialized to black, except in the 2-bpp case, where color 0 is initialized to white and color 1 is initialized to black. The AG_SurfaceRGB() function creates a new surface of w by h pixels using the specified packed-pixel format. In memory, pixels are encoded as contiguous blocks of bitsPerPixel bits, and the bitmasks specified in [RGB]mask are used to retrieve the individual red, green and blue components. The AG_SurfaceRGBA() variant adds an alpha-channel component and implicitely sets the AG_SRCALPHA flag (see AG_SurfaceBlit 3()). AG_SurfaceFromPixelsRGB() and AG_SurfaceFromPixelsRGBA() create a new surface from existing pixel data in the specified format. The AG_SurfaceFromPixelsRGBA() function also sets the AG_SRCALPHA flag. The AG_SurfaceStdGL() function creates a surface in an optimal format for OpenGL textures (packed, 32 bits per pixel with native RGB masks). It also sets the AG_SURFACE_GLTEXTURE flag on the new surface. The function does not use OpenGL itself and is available regardless of whether Agar was compiled with OpenGL support. The AG_SurfaceFromPNG(), AG_SurfaceFromJPEG() and AG_SurfaceFromBMP() functions attempt to load the contents of an image file into a newly-allocated surface. AG_SurfaceFromPNG() and AG_SurfaceFromJPEG() will return an error unless Agar was compiled with support for libpng and libjpeg, respectively. The AG_SurfaceFromSDL() function converts a SDL_Surface(3) to a newly-allocated AG_Surface structure. This function is only available if Agar was compiled with SDL support. The AG_SurfaceSetPalette() function copies count color entries from the colors array, to count slots (starting at offs) in the palette of indexed surface su. AG_SurfaceResize() attempts to resize a surface to the specified dimensions. If insufficient memory is available, the function fails returning -1. When size is increased, the new pixels are left in an uninitialized state. The surface's current clipping rectangle is overwritten by a rectangle covering the entire surface. The AG_SurfaceFree() function releases all resources allocated by the given surface. |
SURFACE OPERATIONS
PIXEL FORMATS
The AG_PixelFormat structure describes a general indexed or packed-pixel surface format. It is defined as follows: typedef struct ag_pixel_format {
AG_Palette *palette; /* For indexed formats */
Uint8 BitsPerPixel; /* Depth (bits/pixel) */
Uint8 BytesPerPixel; /* Depth (bytes/pixel) */
Uint8 Rloss, Gloss, Bloss, Aloss;
Uint8 Rshift, Gshift, Bshift, Ashift;
Uint32 Rmask, Gmask, Bmask, Amask;
Uint32 colorkey; /* Color key pixel */
Uint8 alpha; /* Per-surface alpha value */
} AG_PixelFormat;
The AG_PixelFormatRGB() and AG_PixelFormatRGBA() functions allocate a new structure describing packed-pixel encoding with RGB or RGBA components. The [RGBA]mask arguments specify the bitmasks used to retrieve the individual components from memory. AG_PixelFormatIndexed() creates a new pixel-format structure for indexed pixel encoding. This involves allocating a new palette. The size of this palette is determined by bitsPerPixel, and all palette entries are initialized to black. If 2 bpp is given, the first entry is initialized to white (255,255,255) and the second entry to black (0,0,0). If no memory is available, AG_PixelFormat*() fail returning NULL. AG_PixelFormatCompare() compares two pixel formats. The function returns 0 if the two formats are identical, nonzero if the two formats differ. When comparing color-index formats, the two palettes are compared as well. AG_PixelFormatFree() releases all resources allocated by an AG_PixelFormat structure. |
PACKED-PIXEL SURFACE OPERATIONS
The following routines operate on surfaces in packed-pixel format exclusively.
The AG_GET_PIXEL() macro returns a packed 32-bit representation of the pixel at the given location p in the surface s. AG_GET_PIXEL2() variant locates the pixel in the surface using x,y coordinates. The AG_PUT_PIXEL() and AG_PUT_PIXEL2() write the color c to the pixel at the given location. The AG_BLEND_RGBA() and AG_BLEND_RGBA2() routines perform alpha-blending of the destination pixel against the specified color, where func specifies the blending formula (see AG_BlendFn(3)). The AG_SurfaceBlendPixel() function accepts an AG_Color(3) argument and performs no clipping tests. The AG_PUT_PIXEL2_CLIPPED() and AG_BLEND_RGBA2_CLIPPED() variants of these macros first tests the given coordinates against the clipping rectangle of the surface (see AG_SetClipRect(3)). If the pixel lies outside of the rectangle, the operation is a no-op. The AG_GetPixelRGB() and AG_GetPixelRGBA() functions extract the RGB / RGBA components of a pixel value pixel, in pixel format pf. The AG_MapPixelRGB() and AG_MapPixelRGBA() functions perform the inverse operation, returning the pixel value (in pixel format pf) for the specified RGB / RGBA component values. The AG_GetColor*() and AG_MapColor*() functions are equivalent to AG_GetPixel*() and AG_MapPixel*() except that they accept AG_Color(3) arguments instead of separate component values. Note that the preceding routines are only for use against surfaces in packed RGB/RGBA pixel formats. Passing a color-index format to AG_GetPixel*(), AG_GetColor*(), AG_MapPixel*() or AG_MapColor*() is an illegal operation. |
STRUCTURE DATA
For the
AG_Surface structure:
|
SEE ALSO
| AG_Intro(3), AG_Anim(3), AG_Rect(3) |
HISTORY
| The AG_Surface structure first appeared in Agar 1.3.3. It is modeled after the SDL_Surface of SDL (http://libsdl.org/). |
