Display routines

These functions are declared in the main Allegro header file:

#include <allegro5/allegro.h>

Display creation



An opaque type representing an open display or window.


ALLEGRO_DISPLAY *al_create_display(int w, int h)

Create a display, or window, with the specified dimensions. The parameters of the display are determined by the last calls to al_set_new_display_*. Default parameters are used if none are set explicitly. Creating a new display will automatically make it the active one, with the backbuffer selected for drawing.

Returns NULL on error.

Each display has a distinct OpenGL rendering context associated with it. See al_set_target_bitmap for the discussion about rendering contexts.

See also: al_set_new_display_flags, al_set_new_display_option, al_set_new_display_refresh_rate, al_set_new_display_adapter, al_set_window_position


void al_destroy_display(ALLEGRO_DISPLAY *display)

Destroy a display.

If the target bitmap of the calling thread is tied to the display, then it implies a call to "al_set_target_bitmap(NULL);" before the display is destroyed.

That special case notwithstanding, you should make sure no threads are currently targeting a bitmap which is tied to the display before you destroy it.

See also: al_set_target_bitmap


int al_get_new_display_flags(void)

Get the display flags to be used when creating new displays on the calling thread.

See also: al_set_new_display_flags, al_toggle_display_flag


int al_get_new_display_refresh_rate(void)

Get the requested refresh rate to be used when creating new displays on the calling thread.

See also: al_set_new_display_refresh_rate


void al_get_new_window_position(int *x, int *y)

Get the position where new non-fullscreen displays created by the calling thread will be placed.

See also: al_set_new_window_position


void al_set_new_display_option(int option, int value, int importance)

Set an extra display option, to be used when creating new displays on the calling thread. Display options differ from display flags, and specify some details of the context to be created within the window itself. These mainly have no effect on Allegro itself, but you may want to specify them, for example if you want to use multisampling.

The 'importance' parameter can be either:

The supported options are:

FIXME: document them all in detail

See also: al_set_new_display_flags


int al_get_new_display_option(int option, int *importance)

Retrieve an extra display setting which was previously set with al_set_new_display_option.


void al_reset_new_display_options(void)

This undoes any previous call to al_set_new_display_option on the calling thread.


void al_set_new_display_flags(int flags)

Sets various flags to be used when creating new displays on the calling thread. flags is a bitfield containing any reasonable combination of the following:


Prefer a windowed mode.

Under multi-head X (not XRandR/TwinView), the use of more than one adapter is impossible due to bugs in X and glX. al_create_display will fail if more than one adapter is attempted to be used.


Prefer a fullscreen mode.

Under X the use of more than one FULLSCREEN display when using multi-head X, or true Xinerama is not possible due to bugs in X and glX, display creation will fail if more than one adapter is attempted to be used.


Make the window span the entire screen. Unlike ALLEGRO_FULLSCREEN this will never attempt to modify the screen resolution. Instead the pixel dimensions of the created display will be the same as the desktop.

The passed width and height are only used if the window is switched out of fullscreen mode later but will be ignored initially.

Under Windows and X11 a fullscreen display created with this flag will behave differently from one created with the ALLEGRO_FULLSCREEN flag - even if the ALLEGRO_FULLSCREEN display is passed the desktop dimensions. The exact difference is platform dependent, but some things which may be different is how alt-tab works, how fast you can toggle between fullscreen/windowed mode or how additional monitors behave while your display is in fullscreen mode.

Additionally under X, the use of more than one adapter in multi-head mode or with true Xinerama enabled is impossible due to bugs in X/glX, creation will fail if more than one adapter is attempted to be used.


The display is resizable (only applicable if combined with ALLEGRO_WINDOWED).


Require the driver to provide an initialized OpenGL context after returning successfully.


Require the driver to provide an initialized OpenGL context compatible with OpenGL version 3.0.


If this flag is set, the OpenGL context created with ALLEGRO_OPENGL_3_0 will be forward compatible only, meaning that all of the OpenGL API declared deprecated in OpenGL 3.0 will not be supported. Currently, a display created with this flag will not be compatible with Allegro drawing routines; the display option ALLEGRO_COMPATIBLE_DISPLAY will be set to false.


Require the driver to do rendering with Direct3D and provide a Direct3D device.


Try to create a window without a frame (i.e. no border or titlebar). This usualy does nothing for fullscreen modes, and even in windowed moded it depends on the underlying platform whether it is supported or not.


Let the display generate expose events.

0 can be used for default values.

See also: al_set_new_display_option, al_get_display_option


void al_set_new_display_refresh_rate(int refresh_rate)

Sets the refresh rate to use when creating new displays on the calling thread. If the refresh rate is not available, al_create_display will fail. A list of modes with refresh rates can be found with al_get_num_display_modes and al_get_display_mode.

The default setting is zero (don't care).

See also: al_get_new_display_refresh_rate


void al_set_new_window_position(int x, int y)

Sets where the top left pixel of the client area of newly created windows (non-fullscreen) will be on screen, for displays created by the calling thread. Negative values allowed on some multihead systems.

To reset to the default behaviour, pass (INT_MAX, INT_MAX).

See also: al_get_new_window_position

Display operations


bool al_acknowledge_resize(ALLEGRO_DISPLAY *display)

When the user receives a resize event from a resizable display, if they wish the display to be resized they must call this function to let the graphics driver know that it can now resize the display. Returns true on success.

Adjusts the clipping rectangle to the full size of the backbuffer.

Note that a resize event may be outdated by the time you acknowledge it; there could be further resize events generated in the meantime.

See also: al_resize_display, ALLEGRO_EVENT


void al_flip_display(void)

Copies or updates the front and back buffers so that what has been drawn previously on the currently selected display becomes visible on screen. Pointers to the special back and front buffer bitmaps remain valid and retain their semantics as back and front buffers respectively, although their contents may have changed.

Several display options change how this function behaves:

With ALLEGRO_SINGLE_BUFFER, no flipping is done. You still have to call this function to display graphics, depending on how the used graphics system works.

The ALLEGRO_SWAP_METHOD option may have additional information about what kind of operation is used internally to flip the front and back buffers.

If ALLEGRO_VSYNC is 1, this function will force waiting for vsync. If ALLEGRO_VSYNC is 2, this function will not wait for vsync. With many drivers the vsync behavior is controlled by the user and not the application, and ALLEGRO_VSYNC will not be set; in this case al_flip_display will wait for vsync depending on the settings set in the system's graphics preferences.

See also: al_set_new_display_flags, al_set_new_display_option


ALLEGRO_BITMAP *al_get_backbuffer(ALLEGRO_DISPLAY *display)

Return a special bitmap representing the back-buffer of the display.

Care should be taken when using the backbuffer bitmap (and its sub-bitmaps) as the source bitmap (e.g as the bitmap argument to al_draw_bitmap). Only untransformed operations are hardware accelerated. This consists of al_draw_bitmap and al_draw_bitmap_region when the current transformation is the identity. If the tranformation is not the identity, or some other drawing operation is used, the call will be routed through the memory bitmap routines, which are slow. If you need those operations to be accelerated, then first copy a region of the backbuffer into a temporary bitmap (via the al_draw_bitmap and al_draw_bitmap_region), and then use that temporary bitmap as the source bitmap.


int al_get_display_flags(ALLEGRO_DISPLAY *display)

Gets the flags of the display.

In addition to the flags set for the display at creation time with al_set_new_display_flags it can also have the ALLEGRO_MINIMIZED flag set, indicating that the window is currently minimized. This flag is very platform-dependent as even a minimized application may still render a preview version so normally you should not care whether it is minimized or not.

See also: al_set_new_display_flags


int al_get_display_format(ALLEGRO_DISPLAY *display)

Gets the pixel format of the display.



int al_get_display_height(ALLEGRO_DISPLAY *display)

Gets the height of the display. This is like SCREEN_H in Allegro 4.x.

See also: al_get_display_width


int al_get_display_refresh_rate(ALLEGRO_DISPLAY *display)

Gets the refresh rate of the display.

See also: al_set_new_display_refresh_rate


int al_get_display_width(ALLEGRO_DISPLAY *display)

Gets the width of the display. This is like SCREEN_W in Allegro 4.x.

See also: al_get_display_height


void al_get_window_position(ALLEGRO_DISPLAY *display, int *x, int *y)

Gets the position of a non-fullscreen display.

See also: al_set_window_position


bool al_inhibit_screensaver(bool inhibit)

This function allows the user to stop the system screensaver from starting up if true is passed, or resets the system back to the default state (the state at program start) if false is passed. It returns true if the state was set successfully, otherwise false.


bool al_resize_display(ALLEGRO_DISPLAY *display, int width, int height)

Resize the display. Returns true on success, or false on error. This works on both fullscreen and windowed displays, regardless of the ALLEGRO_RESIZABLE flag.

Adjusts the clipping rectangle to the full size of the backbuffer.

See also: al_acknowledge_resize


void al_set_display_icon(ALLEGRO_DISPLAY *display, ALLEGRO_BITMAP *icon)

Changes the icon associated with the display (window).

Note: If the underlying OS can not use an icon with the size of the provided bitmap, it will be scaled.

See also: al_set_window_title


int al_get_display_option(ALLEGRO_DISPLAY *display, int option)

Return an extra display setting of the display.

See also: al_set_new_display_option


void al_set_window_position(ALLEGRO_DISPLAY *display, int x, int y)

Sets the position on screen of a non-fullscreen display.

See also: al_get_window_position


void al_set_window_title(ALLEGRO_DISPLAY *display, const char *title)

Set the title on a display.

See also: al_set_display_icon


bool al_toggle_display_flag(ALLEGRO_DISPLAY *display, int flag, bool onoff)

Enable or disable one of the display flags. The flags are the same as for al_set_new_display_flags. The only flags that can be changed after creation are:

Returns true if the driver supports toggling the specified flag else false. You can use al_get_display_flags to query whether the given display property actually changed.

See also: al_set_new_display_flags, al_get_display_flags


void al_update_display_region(int x, int y, int width, int height)

Does the same as al_flip_display, but tries to update only the specified region. With many drivers this is not possible, but for some it can improve performance.

The ALLEGRO_UPDATE_DISPLAY_REGION option (see al_get_display_option) will specify the behavior of this function in the display.

See also: al_flip_display, al_get_display_option


bool al_wait_for_vsync(void)

Wait for the beginning of a vertical retrace. Some driver/card/monitor combinations may not be capable of this.

Note how al_flip_display usually already waits for the vertical retrace, so unless you are doing something special, there is no reason to call this function.

Returns false if not possible, true if successful.

See also: al_flip_display


ALLEGRO_EVENT_SOURCE *al_get_display_event_source(ALLEGRO_DISPLAY *display)

Retrieve the associated event source.

Fullscreen display modes



Used for display mode queries. Contains information about a supported fullscreen display mode.

typedef struct ALLEGRO_DISPLAY_MODE {
   int width;          // Screen width
   int height;         // Screen height
   int format;         // The pixel format of the mode
   int refresh_rate;   // The refresh rate of the mode

See also: al_get_display_mode


ALLEGRO_DISPLAY_MODE *al_get_display_mode(int index, ALLEGRO_DISPLAY_MODE *mode)

Retrieves a display mode. Display parameters should not be changed between a call of al_get_num_display_modes and al_get_display_mode. index must be between 0 and the number returned from al_get_num_display_modes-1. mode must be an allocated ALLEGRO_DISPLAY_MODE structure. This function will return NULL on failure, and the mode parameter that was passed in on success.

See also: ALLEGRO_DISPLAY_MODE, al_get_num_display_modes


int al_get_num_display_modes(void)

Get the number of available fullscreen display modes for the current set of display parameters. This will use the values set with al_set_new_display_refresh_rate, and al_set_new_display_flags to find the number of modes that match. Settings the new display parameters to zero will give a list of all modes for the default driver.

See also: al_get_display_mode




Describes a monitors size and position relative to other monitors. x1, y1 will be 0, 0 on the primary display. Other monitors can have negative values if they are to the left or above the primary display.

   int x1;
   int y1;
   int x2;
   int y2;

See also: al_get_monitor_info


int al_get_new_display_adapter(void)

Gets the video adapter index where new displays will be created by the calling thread, if previously set with al_set_new_display_adapter. Otherwise returns ALLEGRO_DEFAULT_DISPLAY_ADAPTER.

See also: al_set_new_display_adapter


void al_set_new_display_adapter(int adapter)

Sets the adapter to use for new displays created by the calling thread. The adapter has a monitor attached to it. Information about the monitor can be gotten using al_get_num_video_adapters and al_get_monitor_info.

To return to the default behaviour, pass ALLEGRO_DEFAULT_DISPLAY_ADAPTER.

See also: al_get_num_video_adapters, al_get_monitor_info


bool al_get_monitor_info(int adapter, ALLEGRO_MONITOR_INFO *info)

Get information about a monitor's position on the desktop. adapter is a number from 0 to al_get_num_video_adapters()-1.

Returns true on success, false on failure.

See also: ALLEGRO_MONITOR_INFO, al_get_num_video_adapters


int al_get_num_video_adapters(void)

Get the number of video "adapters" attached to the computer. Each video card attached to the computer counts as one or more adapters. An adapter is thus really a video port that can have a monitor connected to it.

See also: al_get_monitor_info

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