OpenGL integration

These functions are declared in the following header file:

#include <allegro5/allegro_opengl.h>

al_get_opengl_extension_list

ALLEGRO_OGL_EXT_LIST *al_get_opengl_extension_list(void)

Returns the list of OpenGL extensions supported by Allegro, for the given display.

Allegro will keep information about all extensions it knows about in a structure returned by al_get_opengl_extension_list.

For example:

if (al_get_opengl_extension_list()->ALLEGRO_GL_ARB_multitexture) {
    use it
}

The extension will be set to true if available for the given display and false otherwise. This means to use the definitions and functions from an OpenGL extension, all you need to do is to check for it as above at run time, after acquiring the OpenGL display from Allegro.

Under Windows, this will also work with WGL extensions, and under Unix with GLX extensions.

In case you want to manually check for extensions and load function pointers yourself (say, in case the Allegro developers did not include it yet), you can use the al_have_opengl_extension and al_get_opengl_proc_address functions instead.

al_get_opengl_proc_address

void *al_get_opengl_proc_address(const char *name)

Helper to get the address of an OpenGL symbol

Example:

How to get the function glMultiTexCoord3fARB that comes with ARB's Multitexture extension:

// define the type of the function
   ALLEGRO_DEFINE_PROC_TYPE(void, MULTI_TEX_FUNC,
      (GLenum, GLfloat, GLfloat, GLfloat));
// declare the function pointer
   MULTI_TEX_FUNC glMultiTexCoord3fARB;
// get the address of the function
   glMultiTexCoord3fARB = (MULTI_TEX_FUNC) al_get_opengl_proc_address(
      "glMultiTexCoord3fARB");

If glMultiTexCoord3fARB is not NULL then it can be used as if it has been defined in the OpenGL core library.

Note: Under Windows, OpenGL functions may need a special calling convention, so it's best to always use the ALLEGRO_DEFINE_PROC_TYPE macro when declaring function pointer types for OpenGL functions.

Parameters:

name - The name of the symbol you want to link to.

Return value:

A pointer to the symbol if available or NULL otherwise.

al_get_opengl_texture

GLuint al_get_opengl_texture(ALLEGRO_BITMAP *bitmap)

Returns the OpenGL texture id internally used by the given bitmap if it uses one, else 0.

Example:

bitmap = al_load_bitmap("my_texture.png");
texture = al_get_opengl_texture(bitmap);
if (texture != 0)
    glBindTexture(GL_TEXTURE_2D, texture);

al_get_opengl_texture_size

void al_get_opengl_texture_size(ALLEGRO_BITMAP *bitmap, int *w, int *h)

Retrieves the size of the texture used for the bitmap. This can be different from the bitmap size if OpenGL only supports power-of-two sizes or if it is a sub-bitmap. 0's are returned if the bitmap is not an OpenGL bitmap.

al_get_opengl_texture_position

void al_get_opengl_texture_position(ALLEGRO_BITMAP *bitmap, int *u, int *v)

Returns the u/v coordinates for the top/left corner of the bitmap within the used texture, in pixels.

al_get_opengl_fbo

GLuint al_get_opengl_fbo(ALLEGRO_BITMAP *bitmap)

Returns the OpenGL FBO id internally used by the given bitmap if it uses one, otherwise returns zero. No attempt will be made to create an FBO if the bitmap is not owned by the current display.

The FBO returned by this function will only be freed when the bitmap is destroyed, or if you call al_remove_opengl_fbo on the bitmap.

Note: In Allegro 5.0.0 this function only returned an FBO which had previously been created by calling al_set_target_bitmap. It would not attempt to create an FBO itself. This has since been changed.

See also: al_remove_opengl_fbo, al_set_target_bitmap

al_remove_opengl_fbo

void al_remove_opengl_fbo(ALLEGRO_BITMAP *bitmap)

Explicitly free an OpenGL FBO created for a bitmap, if it has one. Usually you do not need to worry about freeing FBOs, unless you use al_get_opengl_fbo.

See also: al_get_opengl_fbo, al_set_target_bitmap

al_have_opengl_extension

bool al_have_opengl_extension(const char *extension)

This function is a helper to determine whether an OpenGL extension is available on the given display or not.

Example:

bool packedpixels = al_have_opengl_extension("GL_EXT_packed_pixels");

If packedpixels is true then you can safely use the constants related to the packed pixels extension.

Returns true if the extension is available; false otherwise.

al_get_opengl_version

uint32_t al_get_opengl_version(void)

Returns the OpenGL or OpenGL ES version number of the client (the computer the program is running on), for the current display. "1.0" is returned as 0x01000000, "1.2.1" is returned as 0x01020100, and "1.2.2" as 0x01020200, etc.

A valid OpenGL context must exist for this function to work, which means you may not call it before al_create_display.

See also: al_get_opengl_variant

al_get_opengl_variant

int al_get_opengl_variant(void)

Returns the variant or type of OpenGL used on the running platform. This function can be called before creating a display or setting properties for new displays. Possible values are:

ALLEGRO_DESKTOP_OPENGL

Regular OpenGL as seen on desktop/laptop computers.

ALLEGRO_OPENGL_ES

Trimmed down version of OpenGL used on many small consumer electronic devices such as handheld (and sometimes full size) consoles.

See also: al_get_opengl_version

al_set_current_opengl_context

void al_set_current_opengl_context(ALLEGRO_DISPLAY *display)

Make the OpenGL context associated with the given display current for the calling thread. If there is a current target bitmap which belongs to a different OpenGL context, the target bitmap will be changed to NULL.

Normally you do not need to use this function, as the context will be made current when you call al_set_target_bitmap or al_set_target_backbuffer. You might need if it you created an OpenGL "forward compatible" context. Then al_get_backbuffer only returns NULL, so it would not work to pass that to al_set_target_bitmap.

OpenGL configuration

You can disable the detection of any OpenGL extension by Allegro with a section like this in allegro5.cfg:

[opengl_disabled_extensions]
GL_ARB_texture_non_power_of_two=0
GL_EXT_framebuffer_object=0

Any extension which appears in the section is treated as not available (it does not matter if you set it to 0 or any other value).

Allegro version 5.0.4 - Last updated: 2011-08-14 04:29:58 UTC