AllegroGL: Texture Routines

# Texture Routines

AllegroGL provides functions to allow using Allegro BITMAP objects to be used as OpenGL textures. More...

## Texture routines

- int allegro_gl_use_mipmapping (int enable)
    Tell AllegroGL to use Mipmapping or not when generating textures via its functions.
- int allegro_gl_use_alpha_channel (int enable)
    Tell AllegroGL to use Alpha channel or not when generating textures via its functions.
- int allegro_gl_flip_texture (int enable)
    Tell AllegroGL to flip the texture vertically or not when generating textures via its functions, to conform to the usual OpenGL texture coordinate system (increasing upwards).
- int allegro_gl_check_texture (BITMAP *bmp)
    Checks whether the specified bitmap is of the proper size for texturing.
- int allegro_gl_check_texture_ex (int flags, BITMAP *bmp, GLint internal_format)
    Checks whether the specified bitmap is of the proper size for texturing.
- GLint allegro_gl_get_texture_format (BITMAP *bmp)
    Returns the OpenGL internal texture format for this bitmap.
- GLint allegro_gl_set_texture_format (GLint format)
    Sets the color format you'd like OpenGL to use for its textures.
- GLenum allegro_gl_get_bitmap_type (BITMAP *bmp)
    AllegroGL will generate mipmaps for this texture.
- GLenum allegro_gl_get_bitmap_color_format (BITMAP *bmp)
    AllegroGL will generate mipmaps for this texture.
- GLuint allegro_gl_make_texture (BITMAP *bmp)
    Uploads an Allegro BITMAP to the GL driver as a texture.
- GLuint allegro_gl_make_masked_texture (BITMAP *bmp)
    Uploads an Allegro BITMAP to the GL driver as a texture.
- GLuint allegro_gl_make_texture_ex (int flags, BITMAP *bmp, GLint internal_format)
    Uploads an Allegro BITMAP to the GL driver as a texture.
- #define AGL_TEXTURE_MIPMAP 0x01
    AllegroGL will generate mipmaps for this texture.
- #define AGL_TEXTURE_HAS_ALPHA 0x02
    Tell AllegroGL that the bitmap had an alpha channel, so it should be preserved when generating the texture.
- #define AGL_TEXTURE_FLIP 0x04
    Flip the texture on the x-axis.
- #define AGL_TEXTURE_MASKED 0x08
    Generate an alpha channel for this texture, based on the Allegro mask color.
- #define AGL_TEXTURE_RESCALE 0x10
    Tell AllegroGL to allow rescaling of the bitmap.
- #define AGL_TEXTURE_ALPHA_ONLY 0x20
    Tell AllegroGL that the specified BITMAP is an 8-bpp alpha-only BITMAP.

## Detailed Description

AllegroGL provides functions to allow using Allegro BITMAP objects to be used as OpenGL textures.

## Define Documentation

#define AGL_TEXTURE_FLIP 0x04

Flip the texture on the x-axis.

OpenGL uses the bottom-left corner of the texture as (0,0), so if you need your texture to be flipped to make (0,0) the top-left corner, you need to use this flag.

Definition at line 529 of file alleggl.h.

Referenced by allegro_gl_convert_allegro_font_ex().

#define AGL_TEXTURE_MASKED 0x08

Generate an alpha channel for this texture, based on the Allegro mask color.

Make sure the target format supports an alpha channel.

Definition at line 534 of file alleggl.h.

Referenced by allegro_gl_convert_allegro_font_ex().

#define AGL_TEXTURE_RESCALE 0x10

Tell AllegroGL to allow rescaling of the bitmap.

By default, AllegroGL will not rescale the bitmap to fit into a texture. You can override this behavior by using this flag.

Definition at line 540 of file alleggl.h.

## Function Documentation

int allegro_gl_use_mipmapping | ( | int | enable | ) |

Tell AllegroGL to use Mipmapping or not when generating textures via its functions.

This will not affect outside OpenGL states. Default is FALSE (off).

See also:
  allegro_gl_check_texture(), allegro_gl_make_texture() allegro_gl_make_masked_texture()

Parameters:

  | enable | Set to TRUE to enable mipmapping, FALSE otherwise.

Returns:
  The previous mode (either TRUE or FALSE).

Deprecated:

Definition at line 415 of file texture.c.

int allegro_gl_use_alpha_channel | ( | int | enable | ) |

Tell AllegroGL to use Alpha channel or not when generating textures via its functions.

This will not affect outside OpenGL states. Default is FALSE (off).

See also:
  allegro_gl_check_texture(), allegro_gl_make_texture(), allegro_gl_make_masked_texture()

Parameters:

  | enable | Set to TRUE to enable textures with alpha channel, FALSE otherwise.

Returns:
  The previous mode (either TRUE or FALSE).

Deprecated:

Definition at line 439 of file texture.c.

int allegro_gl_flip_texture | ( | int | enable | ) |

Tell AllegroGL to flip the texture vertically or not when generating textures via its functions, to conform to the usual OpenGL texture coordinate system (increasing upwards).

Default is TRUE (on).

See also:
  allegro_gl_check_texture(), allegro_gl_make_texture(), allegro_gl_make_masked_texture()

Parameters:

  | enable | Set to TRUE to enable textures with alpha channel, FALSE otherwise.

Returns:
  The previous mode (either TRUE or FALSE).

Deprecated:

Definition at line 464 of file texture.c.

int allegro_gl_check_texture | ( | BITMAP * | bmp | ) |

Checks whether the specified bitmap is of the proper size for texturing.

This checks for the card's limit on texture sizes.

Important note: allegro_gl_check_texture does not depend on the current state of the texture memory of the driver. This function may return TRUE although there is not enough memory to currently make the texture resident. You may check if the texture is actually resident with glAreTexturesResident().

See also:
  allegro_gl_check_texture_ex(), allegro_gl_make_texture_ex()

Parameters:

  | bmp | The bitmap to be converted to a texture.

Returns:
  TRUE if the bitmap can be made a texture of, FALSE otherwise.

Deprecated:

Definition at line 557 of file texture.c.

References allegro_gl_check_texture_ex().

int allegro_gl_check_texture_ex | ( | int | flags,
|  | BITMAP * | bmp,
|  | GLint | internal_format |
| ) |  |  |

Checks whether the specified bitmap is of the proper size for texturing.

This checks for the card's limit on texture sizes.

The parameters to this function are identical to those of allegro_gl_make_texture_ex().

Important note: allegro_gl_check_texture does not depend on the current state of the texture memory of the driver. This function may return TRUE although there is not enough memory to currently make the texture resident. You may check if the texture is actually resident with glAreTexturesResident().

See also:
  allegro_gl_make_texture_ex()

Parameters:

  | flags | The bitmap conversion flags.
  | bmp | The bitmap to be converted to a texture.
  | internal_format | The internal format to convert to.

Returns:
  TRUE if the bitmap can be made a texture of, FALSE otherwise.

Definition at line 495 of file texture.c.

References allegro_gl_make_texture_ex().

Referenced by allegro_gl_check_texture(), and allegro_gl_convert_allegro_font_ex().

GLint allegro_gl_get_texture_format | ( | BITMAP * | bmp | ) |

Returns the OpenGL internal texture format for this bitmap.

If left to default, it returns the number of color components in the bitmap. Otherwise, it simply returns the user defined value. If the bitmap parameter is NULL, then it returns the currently set format, or -1 if none were previously set. 8 bpp bitmaps are assumed to be alpha channels only (GL_ALPHA8) by default.

See also:
  allegro_gl_set_texture_format(), allegro_gl_make_texture()

Parameters:

  | bmp | The bitmap to get the information of.

Returns:
  The OpenGL internal texture format.

Deprecated:

Definition at line 248 of file texture.c.

Referenced by allegro_gl_convert_allegro_font().

GLint allegro_gl_set_texture_format | ( | GLint | format | ) |

Sets the color format you'd like OpenGL to use for its textures.

You can pass any of the available GL_* constants that describe the internal format (GL_ALPHA4...GL_RGBA16). It is recommended that you check for the availability of the format from the client, using allegro_gl_opengl_version(). No checking will be done as to the validity of the format. The format is a recommendation to the driver, so there is no guarentee that the actual format used will be the one you chose - this is implementation dependant. This call will affect all subsequent calls to allegro_gl_make_texture() and allegro_gl_make_masked_texture().

To revert to the default AllegroGL format, pass -1 as the format.

See also:
  allegro_gl_get_texture_format()

Parameters:

  | format | The OpenGL internal texture format.

Returns:
  The previous value of the texture format.

Deprecated:

Definition at line 282 of file texture.c.

GLuint allegro_gl_make_texture | ( | BITMAP * | bmp | ) |

Uploads an Allegro BITMAP to the GL driver as a texture.

Deprecated:

See also:
  allegro_gl_make_texture_ex()

Definition at line 1383 of file texture.c.

References allegro_gl_make_texture_ex().

GLuint allegro_gl_make_masked_texture | ( | BITMAP * | bmp | ) |

Uploads an Allegro BITMAP to the GL driver as a texture.

Deprecated:

See also:
  allegro_gl_make_texture_ex()

Definition at line 1402 of file texture.c.

References allegro_gl_make_texture_ex().

GLuint allegro_gl_make_texture_ex | ( | int | flags,
|  | BITMAP * | bmp,
|  | GLint | internal_format |
| ) |  |  |

Uploads an Allegro BITMAP to the GL driver as a texture.

The bitmap must be a memory bitmap (note that it can be a subbitmap).

Each bitmap will be converted to a single texture object, with all its size limitations imposed by the video driver and hardware.

The bitmap should conform to the size limitations imposed by the video driver. That is, if ARB_texture_non_power_of_two is not supported, then the BITMAP must be power-of-two sized. Otherwise, AllegroGL will pick the best format for the bitmap.

The original bitmap will NOT be modified.

The flags parameter controls how the texture is generated. It can be a logical OR (|) of any of the following:

AGL_TEXTURE_MIPMAP AGL_TEXTURE_HAS_ALPHA AGL_TEXTURE_FLIP AGL_TEXTURE_MASKED AGL_TEXTURE_RESCALE

AllegroGL will create a texture with the specified texel format. The texel format should be any of the valid formats that can be specified to glTexImage2D(). No validity checks will be performed by AllegroGL. If you want AllegroGL to automatically determine the format to use based on the BITMAP, use -1 as the format specifier.

A valid GL Rendering Context must have been established, which means you cannot use this function before having called set_gfx_mode() with a valid OpenGL mode.

Important note: on 32 bit bitmap in RGBA mode, the alpha channel created by Allegro is set to all 0 by default. This will cause the texture to not show up in 32bpp modes if alpha is set. You will need to fill in the alpha channel manually if you need an alpha channel.

Parameters:

  | bmp | The bitmap to be converted to a texture.
  | flags | The conversion flags.
  | internal_format | The texture format to convert to.

Returns:
  GLuint The texture handle, or 0 on failure

Definition at line 1165 of file texture.c.

References allegro_gl_extensions_GL.

Referenced by allegro_gl_check_texture_ex(), allegro_gl_convert_allegro_font_ex(), allegro_gl_make_masked_texture(), and allegro_gl_make_texture().